vb Code:
Public Class Form1
Dim startTime As TimeSpan
Dim clicks As New List(Of Integer)
Dim listIndex As Integer = 0
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim endTime As TimeSpan = Now.TimeOfDay
Dim elapsed As TimeSpan = endTime - startTime
If elapsed.TotalMinutes >= 60 Then
clicks.Add(0)
startTime = startTime.Add(New TimeSpan(1, 0, 0))
listIndex += 1
NumericUpDown1.Maximum += 1
NumericUpDown1.Value = NumericUpDown1.Maximum
End If
clicks(listIndex) += 1
Label1.Text = String.Format("{0} hour clicks = {1}", getNumberWithSuffix(CInt(NumericUpDown1.Value) + 1), clicks(CInt(NumericUpDown1.Value)))
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
startTime = Now.TimeOfDay
NumericUpDown1.Maximum = 0
clicks.Add(0)
End Sub
Private Sub NumericUpDown1_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NumericUpDown1.ValueChanged
Label1.Text = String.Format("{0} hour clicks = {1}", getNumberWithSuffix(CInt(NumericUpDown1.Value) + 1), clicks(CInt(NumericUpDown1.Value)))
End Sub
Private Function getNumberWithSuffix(ByVal x As Integer) As String
If x > 100 Then Return "Unsupported"
Select Case x
Case 1, 21, 31, 41, 51, 61, 71, 81, 91
Return x.ToString & "st"
Case 2, 22, 32, 42, 52, 62, 72, 82, 92
Return x.ToString & "nd"
Case 3, 23, 33, 43, 53, 63, 73, 83, 93
Return x.ToString & "rd"
Case Else
Return x.ToString & "th"
End Select
End Function
End Class