Learning Just About Timers In VB.NET

Опубликовано: 20 Март 2026
на канале: Andrews Roy
4,945
9

Here's a tutorial that will show you how to make a timer that really is based on seconds changing...

Unlike using timers that go off every 1000ms my application bases itself off, real seconds changing.

Things You Might Need...

1. (5) Labels (LYears, LDays, LHours, LMinutes, LSeconds)
2. (1) Timer (TSec)
3. (5) Group Boxes (Years, Days, Hours, Minutes, Seconds)
4. (1) TextBox (LSec) "Make Not Visible at Compile Time"

----------------------------------------------------------------------

Form1.vb

Private Sub LSec_TextChanged

LSecond.text = LSeconds.text + 1

End Sub

Private Sub TSec_Tick

LSec.Text = TimeOfDay.Second

'If LSeconds Equals 60, It Equals 0, add 1 To LMinutes
If LSeconds.Text = 60 Then
LSeconds.Text = "00"
LMinutes.Text = LMinutes.Text + 1

'If LMiniutes Equals 60, It Equals 0, add 1 to LHours
If LMinutes.Text = 60 Then
LMinutes.Text = 0
LHours.Text = LHours.Text + 1

'If LHours Equals 24, It Equals 0, add 1 to LDays
If LHours.Text = 24 Then
LHours.Text = 0
LDays.Text = LDays.Text + 1

'If LDays Equals 365, and LHours Equals 6, add 1 to years
If LDays.Text = 365 And LHours.Text = 6 Then
LDays.Text = 0
LHours.Text = 0
LMinutes.Text = 0
LSeconds.Text = 0
LYears.Text = LYears.Text + 1

End If
End If
End If
End If
End Sub