|
-
Jul 26th, 2012, 09:27 AM
#1
Thread Starter
Member
Working with time
Hello,
What I am trying to do is find a method to find out how often something happends within a time frame. What I have is a TotalTime (total spent on form). And a CompleteButton. What I want to figure out is how many times CompleteButton is clicked in an hour.
Thanks for any advice...
-
Jul 26th, 2012, 09:57 AM
#2
Re: Working with time
try this:
vb Code:
Public Class Form1
Dim startTime As New TimeSpan(16, 0, 0) '4 o'clock
Dim endTime As New TimeSpan(17, 0, 0) '5 o'clock
Dim clicks As Integer = 0
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If Now.TimeOfDay >= startTime And Now.TimeOfDay <= endTime Then
clicks += 1
Label1.Text = clicks.ToString
End If
End Sub
End Class
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Jul 26th, 2012, 10:07 AM
#3
Re: Working with time
Add a global variable
Dim Count As Int16 = 0
Take the time when the application starts (use the form load event)
Dim Start as DateTime= Now
Add one hour for Stop
In the button click event
If Stop > Now increment Count and display the running total
Alternatively keep the count running, take the time at the end of an arbitrary period and divide count by the hours expired.
-
Jul 26th, 2012, 10:09 AM
#4
Re: Working with time
 Originally Posted by .paul.
try this:
Yeah, something like that. (How does he do that so quick?)
-
Jul 26th, 2012, 10:20 AM
#5
Thread Starter
Member
Re: Working with time
Thank you both very much.
I think I might have not properly said what I was trying to do because you both answered me perfect.
I guess my goal is to track an employee's production. So the theory I have came up with is that Production = Total Time / Clicks ...... and then all that broken down to hours... and the program has many forms... so i want to track how long they are on say form1 and how many times they click it within the total time frame...if that makes sense
-
Jul 26th, 2012, 01:15 PM
#6
Re: Working with time
ok. that's slightly more complicated. i used a button, a numericupdown, + a label.
the number of clicks is stored per hour, starting when you load the app. if there is more than 1 hour, you can select a different hour with the numericupdown.
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
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Jul 26th, 2012, 01:21 PM
#7
Thread Starter
Member
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|