| | |
Visual Basic Timer/Clock/Countdown.
![]() |
•
•
Join Date: Apr 2004
Posts: 14
Reputation:
Solved Threads: 0
Well I have to make a microwave program in Visual Basic for school.
I can't seem to find anything in the index that will help me with the timer/countdown. I found TimeOfDay() and was going to use that for the clock but I can't figure out how I would make the clock so it would constantly change and display the right time as a label on the form. I have no idea what I am searching for either so if you guys could help me out thanks. :mrgreen:
I can't seem to find anything in the index that will help me with the timer/countdown. I found TimeOfDay() and was going to use that for the clock but I can't figure out how I would make the clock so it would constantly change and display the right time as a label on the form. I have no idea what I am searching for either so if you guys could help me out thanks. :mrgreen:
•
•
•
•
Originally Posted by Transworld
Well I have to make a microwave program in Visual Basic for school.
I can't seem to find anything in the index that will help me with the timer/countdown. I found TimeOfDay() and was going to use that for the clock but I can't figure out how I would make the clock so it would constantly change and display the right time as a label on the form. I have no idea what I am searching for either so if you guys could help me out thanks. :mrgreen:
Mark Nemtsas
Time and Billing Software - Time Tracking Software - Roller Shutters - Roller Blinds -
Baby Books
Time and Billing Software - Time Tracking Software - Roller Shutters - Roller Blinds -
Baby Books
Google is your frieeeeend.
Mark Nemtsas
Time and Billing Software - Time Tracking Software - Roller Shutters - Roller Blinds -
Baby Books
Time and Billing Software - Time Tracking Software - Roller Shutters - Roller Blinds -
Baby Books
•
•
Join Date: Dec 2004
Posts: 1
Reputation:
Solved Threads: 0
did i hear that proply u cant get a clock 2 show the correct time of day if so
stick a timer and a label on the form the code is
thats in vb6 if your talkin about sumthink else soz i come in l8 o and the timer fuction can b used as a count down in a label like
stick a timer and a label on the form the code is
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
Private Sub Form_Load() Timer1.Interval = 100 Label1.Caption = "" End Sub Private Sub Timer1_Timer() Label1.Caption = Time End Sub
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
Private Sub Form_Load() Timer1.Interval = 1000 Label1.Caption = "100" End Sub Private Sub Timer1_Timer() if label1.caption = 0 then timer1.enabled = false msgbox ("100 secs is up") else Label1.Caption = label1.caption - 1 end if End Sub
•
•
Join Date: Dec 2005
Posts: 2
Reputation:
Solved Threads: 0
depending on timer may effect the application, it reacts differently in different operating environments, i hope the code given below may help you
'code starts from here
Private Declare Sub Sleep lib "kernel32" (ByVal dwMilliseconds as long)
'Command Click
Dim lngLoopCntr as long
Dim lngMilliSecs as Long
lngLoopCntr=0 ' although it initializes to 0 , but it is a gud practise to initialize variable
lngMilliSecs = 10000 ' 10 Seconds
Do While True
Sleep 10
lngLoopCntr=lngLoopCntr + 10
if lngLoopCntr > lngMilliSecs then exit Do
Loop
Msgbox "Done"
'Code Ends :surprised
'code starts from here
Private Declare Sub Sleep lib "kernel32" (ByVal dwMilliseconds as long)
'Command Click
Dim lngLoopCntr as long
Dim lngMilliSecs as Long
lngLoopCntr=0 ' although it initializes to 0 , but it is a gud practise to initialize variable
lngMilliSecs = 10000 ' 10 Seconds
Do While True
Sleep 10
lngLoopCntr=lngLoopCntr + 10
if lngLoopCntr > lngMilliSecs then exit Do
Loop
Msgbox "Done"
'Code Ends :surprised
•
•
Join Date: Dec 2004
Posts: 207
Reputation:
Solved Threads: 7
•
•
•
•
Originally Posted by sra1kesha
depending on timer may effect the application, it reacts differently in different operating environments, i hope the code given below may help you
'code starts from here
Private Declare Sub Sleep lib "kernel32" (ByVal dwMilliseconds as long)
'Command Click
Dim lngLoopCntr as long
Dim lngMilliSecs as Long
lngLoopCntr=0 ' although it initializes to 0 , but it is a gud practise to initialize variable
lngMilliSecs = 10000 ' 10 Seconds
Do While True
Sleep 10
lngLoopCntr=lngLoopCntr + 10
if lngLoopCntr > lngMilliSecs then exit Do
Loop
Msgbox "Done"
'Code Ends :surprised
The problem is that Windows takes a time-out every 55 milliseconds to do its mousekeeping, and all I/O must occur during the mouskeeping period.
When the real-world event which is supposed to start the interval occurs, Windows won't let the computer program know about it until the program's jiffy is over and Windows does the I/O during the mousekeeping period. So the timer starts late.
Then, after the interval ends, Windows won't let the command be sent to the real-world equipment until the program's jiffy ends and Windows does the I/O during the mousekeeping period. So the timed interval ends late.
The total elapsed time is 55 ms times a random number in the range [0..1), plus 55 ms times the next highest integer of the quotient of the desired interval divided by 55 ms. The random number term represents the time left in the 55 ms jiffy when the real-world event actually occurs, and the other term represents the actual time elapsed from the start of the timer to the output of the command to the real-world equipment.
So, no matter what interval I really need, I get a longer interval which is at least 55 ms long. The process is done wrong, and the desired result is not achieved.
The intervals I need are based on real-world constants, and cannot be changed to accommodate Windows.
Microsoft made computers totally useless for my application when it changed from MS-DOS to Windows.
You can use the TimeOfDay() function. Store the TimeOfDay into a variable called present when the start button is hit. And also store that value plus the number of seconds the user inputted into another variable.
Private Sub StartButton (...) handles click
future = present + seconds_to_count_down
And have the display equal the future minus the present time. The present time needs to be refreshed with a timer.
Private Sub Timer1 (...) {
present = TimeOfDay
}
Sorry if this is a bit indescript. I don't know the variable types for these things off hand. I'm more of a C++ person.
Private Sub StartButton (...) handles click
future = present + seconds_to_count_down
And have the display equal the future minus the present time. The present time needs to be refreshed with a timer.
Private Sub Timer1 (...) {
present = TimeOfDay
}
Sorry if this is a bit indescript. I don't know the variable types for these things off hand. I'm more of a C++ person.
pokerponcho
![]() |
Other Threads in the Visual Basic 4 / 5 / 6 Forum
- Previous Thread: packaging and transfering VB6 and MS acess database
- Next Thread: inbox in visual basic 6.0
| Thread Tools | Search this Thread |
.net .net2005 .net2008 6 2005 abrupt access add advertising array assembly auto botnet browser browserproblems buttons c# c++ center character class click code compile compression conversion cool creat csv database databasesearch date design encryption explorer file form format fraud geek gnome guess html inboxinvb java karmic kioti16 koala lapse linux load math monitor mozilla netbeans news number objectinsert offline password ppc program programing programmer protection python reference save schedule simple single stream string super survey time timespan tlapse troubleshoot ubuntu unix user usercontrol vb vb.net vb6 vb6.0 vbnet view vista visual visualbasic visualbasic.net visualbasic6 visualstudio.net visualstudio2008 web windows wpf xp







