Private intStart As Integer 'Holds the starting number.
Private intEnd As Integer 'Holds the ending number.
Private intCurrent As Integer 'Holds the current number we are at when counting.
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'Get the numbers into our class variables
intStart = Integer.Parse(TextBox1.Text.Trim())
intEnd = Integer.Parse(TextBox2.Text.Trim())
intCurrent = intStart
Label1.Text = intCurrent.ToString()
'Check that the start number is smaller than the end number.
If intStart < intEnd Then
'Set an interval to the timer and start it.
Timer1.Interval = 1000
Timer1.Start()
Else
MessageBox.Show("The start number has to be less than the end number.")
End If
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
'Check to see if the current number is still less than the end number.
If intCurrent < intEnd Then
'Since it is less, add 100 to it.
intCurrent += 100
'Make sure that by adding 100 to it, we didn't pass
'the end number. If we did, then we set the current
'number equal to the end number.
If intCurrent > intEnd Then
intCurrent = intEnd
End If
'Display the current number.
Label1.Text = intCurrent.ToString()
Else
'Our current number is no longer less than the end number.
'We need to stop the timer now.
Timer1.Stop()
End If
End Sub