Hi experts! I'm a newbie in this site and i wanted to ask for help in VB timers. We have a simple system about time monitoring.

May i ask, what code will i use. if i clicked a command button (time in), it will run the time. then if i clicked on time out, the timer will stop then i'll click on another button to get the time intervals where i'll bill the user on time spent.

please help me..

thanks!

purplestar86

Hi

Keep 2 Form Level Variables:
Difference Shown is in Seconds Divide By 60 and Convert to Minutes.

Dim StartTime As Date
Dim EndTime As Date
'
Private Sub cmdStart_Click()
    StartTime = Now
End Sub
'
Private Sub cmdEnd_Click()
    EndTime = Now
    MsgBox DateDiff("s", StartTime, EndTime)
End Sub

I hope it is clear

Regards
Veena

Or with only one button:

Dim StartTime As Date
'
Private Sub cmdStart_Click()
    if StartTime = 0 then
        StartTime = Now
        cmdStart.caption = "Stop Timer"
    else
        MsgBox DateDiff("s", StartTime, EndTime)
        StartTime = 0
        cmdStart.caption = "Start Timer"
    end if
End Sub

If course you can store the difference in a variable and use it elsewhere, too.

Hi,

Its OK to use Single Command Button,
but not OK to Check for StartTime = 0 .
As StartTime =0 means 12:00:00 AM.
What If the user clicks Stop At exactly that time?


In that case, u have to Check with the Caption of Command Button like

If cmdStart.caption = "Start Timer" Then

Well.. I'am not trying to Argue with the moderator, but trying to tell one of the rare possibilities.

Regards
Veena

i want to set a timer from a button click to run for ten minutes then go off, but can only get the timer in vb6 to run for 10000 milliseconds ! any help would be great.
Thanks Newbie Dogfish

Its OK to use Single Command Button,
but not OK to Check for StartTime = 0 .
As StartTime =0 means 12:00:00 AM.
What If the user clicks Stop At exactly that time?

Good point. I'm used to C where the time returns time from a specific date. I forgot VB's time is 24hrs.

Good solution checking the caption... :)

Well.. I'am not trying to Argue with the moderator, but trying to tell one of the rare possibilities.

You can correct any moderator when they are wrong. We're just as human as you. Well some mods are. There are a couple I'm not so sure about :confused:

Hi,

Set these properties for Timer Control :
Interval = 10000
Enabled = False
Place A Command Button cmdStart
Caption ="Start"
Keep a Form Level Variable MyTime

Dim MyTime As Long
 
Private Sub cmdStart_Click()
    MyTime = 0
    Timer1.Enabled =True
    cmdStart.Enabled = False    
End Sub
 
Private Sub Timer1_Timer()
    MyTime = MyTime +1
    If MyTime >= 60 Then 
        MyTime = 0
        Timer1.Enabled = False
        MsgBox "Time Out!!"
        cmdStart.Enabled = True
    End If
End Sub

I Hope It is Clear.

Regards
Veena

Hi :),

What is your name? I could give you an example related to VB Timer. I hope it can help. I have built up an application for an Internet Cafe (calculate the duration, printing,scaning,burning the cd, internet usage, soft drink fee etc...); I can assure you that my application is flexible. If you are interested, I'll update to your demand and we can negotiate the cost. I'll show you the sample.

Here it is: you have to use Timer control

For example. Button Start or Time in:

cmdstart_clidk()

If stop1 = True Then
hou2 = 0: min2 = 0: sec2 = 0
txtpc1 = Format(hou2, "00") & ":" & Format(min2, "00") & ":" & Format(sec2, "00")
End If
Timer2.Interval = 1000 '(call Timer2_Timer)

'Important Note: You have to declare min2,hou2 and sec2 in the General Declaration

Timer2_Timer()

txtpc1 = Format(hou2, "00") & ":" & Format(min2, "00") & ":" & Format(sec2, "00")
If sec2 <= 58 Then sec2 = Format(sec2 + 1, "00")
If sec2 = 59 Then
sec2 = 0
min2 = min2 + 1
End If
If min2 = 59 Then
min2 = 0
hou2 = hou2 + 1
End If


Button Stop or Time out:

Private Sub cmdstop1_Click()
Timer2.Interval = 0
stop1 = True
End Sub


If you have any queries, please feel free to ask me at any time at email goes bye-bye
. Thank you!

Moniroth

Hello to eveyone and to all who replied on this thread! I took a break from school work, and I'll be starting to work on our system hopefully by tomorrow.

Thanks for all your help!
I'll be trying out the codes you've shared and get back and ask again if i encounter troubles on our system :)

I appreciate your knowledge, time and effort replying on this thread entry! Thank you so much!

A Blessed and Happy New Year to all! :)


purplestar86 - Tine

hi all

i want time difference between dates in milli-seconds...

thnx in advance,

ashu

Hi,

You can use DateDiff function in which you can get difference in seconds multiply these seconds with 1000, you will get milliseconds.

Hope this is what you want.
Regards,
Shrinivas

hi,
try below coding to find out the time difference

Dim starttime As Date
Private Sub Command1_Click()
If Command1.Caption = "Start" Then
starttime = Text1.Text
Timer1.Enabled = True
Command1.Caption = "Stop"
ElseIf Command1.Caption = "Stop" Then
Text2.Text = DateDiff("s", starttime, Text1.Text)
Timer1.Enabled = False
Command1.Caption = "Start"
End If
End Sub

Private Sub Form_Load()
Command1.Caption = "Start"
Text1.Text = DateTime.Time
Timer1.Enabled = False
End Sub

Private Sub Timer1_Timer()
Text1.Text = DateTime.Time
End Sub

shailu

hi shailu,

actually the smallest unit for DateDiff is seconds..and i wanted result in MilliSeconds
thts y i used the API..

hi.. uhmmm.. just have a question.. the topic here is an INTERNET CAFE SYSTEM.. right?...

i just want to ask if.. how will you handle if many will log in..

how will the timer function.. or how will you put the timing process in a database..

it can be stored in each pC (the timer process) and the server will just get the information from the clients and saving it in the server database..


is there any other way or method.. im would like to use SQL for the dbase

hi

u can store the timer values for each machine in the database, for rg.


MachineIP varchar,
StartTime DateTime,
StopTime DateTime

u can remove StopTime field if u dont wanna keep log
just update the StartTime, everytime a new user logs on

thanks..

how can each computer respond to the system.. uhmm.. IP ADDRESSing? how can you know and display the IP ADDRESS of your computer in VB 6.0

Hi experts! I'm a newbie in this site and i wanted to ask for help in VB timers. We have a simple system about time monitoring.

May i ask, what code will i use. if i clicked a command button (time in), it will run the time. then if i%2

This question has already been answered. Start a new discussion instead.