Visual Basic Timer/Clock/Countdown.

Reply

Join Date: Apr 2004
Posts: 14
Reputation: Transworld is an unknown quantity at this point 
Solved Threads: 0
Transworld Transworld is offline Offline
Newbie Poster

Visual Basic Timer/Clock/Countdown.

 
0
  #1
Nov 20th, 2004
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:
Reply With Quote Quick reply to this message  
Join Date: Jul 2004
Posts: 200
Reputation: mnemtsas is an unknown quantity at this point 
Solved Threads: 1
mnemtsas's Avatar
mnemtsas mnemtsas is offline Offline
Junior Poster

Re: Visual Basic Timer/Clock/Countdown.

 
0
  #2
Nov 22nd, 2004
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:
Try using the timer control.
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 14
Reputation: Transworld is an unknown quantity at this point 
Solved Threads: 0
Transworld Transworld is offline Offline
Newbie Poster

Re: Visual Basic Timer/Clock/Countdown.

 
0
  #3
Nov 24th, 2004
Yeah, I found it. I think I got over stressed because my assignment was due soon so I resorted to the forum too fast. I found it on Google in almost no time at all. Guess in the rush I forgot about the Google power. Thanks though. :mrgreen:
Reply With Quote Quick reply to this message  
Join Date: Jul 2004
Posts: 200
Reputation: mnemtsas is an unknown quantity at this point 
Solved Threads: 1
mnemtsas's Avatar
mnemtsas mnemtsas is offline Offline
Junior Poster

Re: Visual Basic Timer/Clock/Countdown.

 
0
  #4
Nov 24th, 2004
Google is your frieeeeend.
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 1
Reputation: therealmkb is an unknown quantity at this point 
Solved Threads: 0
therealmkb therealmkb is offline Offline
Newbie Poster

Re: Visual Basic Timer/Clock/Countdown.

 
0
  #5
Dec 10th, 2004
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

Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Private Sub Form_Load()
  2. Timer1.Interval = 100
  3. Label1.Caption = ""
  4. End Sub
  5.  
  6. Private Sub Timer1_Timer()
  7. Label1.Caption = Time
  8. End Sub
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

Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Private Sub Form_Load()
  2. Timer1.Interval = 1000
  3. Label1.Caption = "100"
  4. End Sub
  5.  
  6. Private Sub Timer1_Timer()
  7. if label1.caption = 0 then
  8. timer1.enabled = false
  9. msgbox ("100 secs is up")
  10. else
  11. Label1.Caption = label1.caption - 1
  12. end if
  13. End Sub
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 207
Reputation: Real-tiner is an unknown quantity at this point 
Solved Threads: 8
Real-tiner Real-tiner is offline Offline
Posting Whiz in Training

Re: Visual Basic Timer/Clock/Countdown.

 
0
  #6
Dec 17th, 2004
I did this several years ago in QuickBasic 4.5.

I put the call to read the time inside a loop, which repeated until the desired time appeared. Of course, I needed millisecond accurtacy.

Now how can I do this under Windows XP?
Reply With Quote Quick reply to this message  
Join Date: Dec 2005
Posts: 2
Reputation: sra1kesha is an unknown quantity at this point 
Solved Threads: 0
sra1kesha sra1kesha is offline Offline
Newbie Poster

Re: Visual Basic Timer/Clock/Countdown.

 
0
  #7
Dec 7th, 2005
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
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 207
Reputation: Real-tiner is an unknown quantity at this point 
Solved Threads: 8
Real-tiner Real-tiner is offline Offline
Posting Whiz in Training

Re: Visual Basic Timer/Clock/Countdown.

 
0
  #8
Dec 7th, 2005
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
I need to create time intervals in the millisecond range (e.g. 30 ms), not the seconds range. These are necessary for real-time control of equipment.

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.
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 2,413
Reputation: Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough 
Solved Threads: 211
Team Colleague
Comatose's Avatar
Comatose Comatose is offline Offline
Taboo Programmer

Re: Visual Basic Timer/Clock/Countdown.

 
0
  #9
Dec 7th, 2005
Reply With Quote Quick reply to this message  
Join Date: Nov 2005
Posts: 10
Reputation: pokerponcho is an unknown quantity at this point 
Solved Threads: 0
pokerponcho's Avatar
pokerponcho pokerponcho is offline Offline
Newbie Poster

Re: Visual Basic Timer/Clock/Countdown.

 
0
  #10
Dec 8th, 2005
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.
pokerponcho
Reply With Quote Quick reply to this message  
Reply

Tags
click, program, save, time, vb

Message:



Other Threads in the Visual Basic 4 / 5 / 6 Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC