943,712 Members | Top Members by Rank

Ad:
You are currently viewing page 1 of this multi-page discussion thread
Nov 20th, 2004
-3

Visual Basic Timer/Clock/Countdown.

Expand Post »
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:
Reputation Points: 11
Solved Threads: 0
Newbie Poster
Transworld is offline Offline
14 posts
since Apr 2004
Nov 22nd, 2004
0

Re: Visual Basic Timer/Clock/Countdown.

Quote 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.
Reputation Points: 16
Solved Threads: 1
Posting Whiz in Training
mnemtsas is offline Offline
200 posts
since Jul 2004
Nov 24th, 2004
0

Re: Visual Basic Timer/Clock/Countdown.

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:
Reputation Points: 11
Solved Threads: 0
Newbie Poster
Transworld is offline Offline
14 posts
since Apr 2004
Nov 24th, 2004
0

Re: Visual Basic Timer/Clock/Countdown.

Google is your frieeeeend.
Reputation Points: 16
Solved Threads: 1
Posting Whiz in Training
mnemtsas is offline Offline
200 posts
since Jul 2004
Dec 10th, 2004
0

Re: Visual Basic Timer/Clock/Countdown.

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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
therealmkb is offline Offline
1 posts
since Dec 2004
Dec 17th, 2004
0

Re: Visual Basic Timer/Clock/Countdown.

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?
Reputation Points: 11
Solved Threads: 8
Posting Whiz in Training
Real-tiner is offline Offline
207 posts
since Dec 2004
Dec 7th, 2005
0

Re: Visual Basic Timer/Clock/Countdown.

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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
sra1kesha is offline Offline
2 posts
since Dec 2005
Dec 7th, 2005
0

Re: Visual Basic Timer/Clock/Countdown.

Quote 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.
Reputation Points: 11
Solved Threads: 8
Posting Whiz in Training
Real-tiner is offline Offline
207 posts
since Dec 2004
Dec 7th, 2005
0

Re: Visual Basic Timer/Clock/Countdown.

Team Colleague
Reputation Points: 361
Solved Threads: 214
Taboo Programmer
Comatose is offline Offline
2,413 posts
since Dec 2004
Dec 8th, 2005
-1

Re: Visual Basic Timer/Clock/Countdown.

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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
pokerponcho is offline Offline
10 posts
since Nov 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Visual Basic 4 / 5 / 6 Forum Timeline: how to install my program
Next Thread in Visual Basic 4 / 5 / 6 Forum Timeline: How to Convert Dotted Decimal to Binary and Vice Versa in VB6





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC