954,559 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Visual Basic Timer/Clock/Countdown.

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:

Transworld
Newbie Poster
14 posts since Apr 2004
Reputation Points: 11
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:

Try using the timer control.

mnemtsas
Posting Whiz in Training
200 posts since Jul 2004
Reputation Points: 16
Solved Threads: 1
 

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:

Transworld
Newbie Poster
14 posts since Apr 2004
Reputation Points: 11
Solved Threads: 0
 

Google is your frieeeeend.

mnemtsas
Posting Whiz in Training
200 posts since Jul 2004
Reputation Points: 16
Solved Threads: 1
 

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

Private Sub Form_Load()
     Timer1.Interval = 100
     Label1.Caption = ""
End Sub

Private Sub Timer1_Timer()
     Label1.Caption = Time
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

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
therealmkb
Newbie Poster
1 post since Dec 2004
Reputation Points: 10
Solved Threads: 0
 

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?

Real-tiner
Posting Whiz in Training
207 posts since Dec 2004
Reputation Points: 11
Solved Threads: 8
 

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

sra1kesha
Newbie Poster
2 posts since Dec 2005
Reputation Points: 10
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

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.

Real-tiner
Posting Whiz in Training
207 posts since Dec 2004
Reputation Points: 11
Solved Threads: 8
 
Comatose
Taboo Programmer
Team Colleague
2,910 posts since Dec 2004
Reputation Points: 361
Solved Threads: 215
 

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

Isn't there an API function that lets you do a more detailed timer function?

mjwest10
Light Poster
27 posts since Feb 2007
Reputation Points: 10
Solved Threads: 3
 

THIS IS GREAT!!!!!!!!


know what, im on a great dilemma about this...


i've been trying this myself, this countdown thingy....


ive made so many circus tricks but funny, these are the only codes i needed...


so thank you so much to you who posted this!


please mail me in my account SNIP

i will be pleased to know that you have read my post....

memaine
Newbie Poster
1 post since Sep 2009
Reputation Points: 3
Solved Threads: 0
 

Do you need to show the actual time or the countdown of a timer? If time then the format i.e. hour:minute:seconds?

AndreRet
Senior Poster
3,922 posts since Jan 2008
Reputation Points: 334
Solved Threads: 350
 

You can user Timer Function
dim t as double
t=timer

do while (timer-t)<10.1

loop

Timer-T Return how many Second and milisec in diff
Timer return how manu sec passed in the day
hour=timer/3600
minute=(timer mod 3600) / 60
second=((timer mod 3600) mod 60)
milisec=clng(timer)-timer

omoridi
Junior Poster in Training
72 posts since Sep 2009
Reputation Points: 10
Solved Threads: 10
 

Calculator overview
You can use Calculator to perform any of the standard operations for which you would normally use a handheld calculator. Calculator performs basic arithmetic, such as addition and subtraction, as well as functions found on a scientific calculator, such as logarithms and factorials.

gkhfv,h@
Newbie Poster
1 post since Oct 2009
Reputation Points: 10
Solved Threads: 0
 

[LIST]
[/

<ul><li><ul><li><ul><li><pre><code>[TEX][/TEX]</code></pre>
<ul><li><ul><li><ul><li><ul><li><ul><li><ul><li>LIST]</li>
</ul></li>
</ul></li>
</ul></li>
</ul></li>
</ul></li>
</ul></li>
</ul></li>
</ul></li>
</ul>


baz

marc badz
Newbie Poster
1 post since Dec 2009
Reputation Points: 10
Solved Threads: 0
 

i need timer code in test to limit the time for 1hour
how can i do this?

eng7asebat
Newbie Poster
6 posts since May 2010
Reputation Points: 10
Solved Threads: 0
 

create a timer with interval 1000
and check in timer event
time is yours or not.

like t is your time = 9:00 pm
if time >=t then
ok

omoridi
Junior Poster in Training
72 posts since Sep 2009
Reputation Points: 10
Solved Threads: 10
 

@ omoridi
i can't understand
plz explane more
i have a timer and make interval 1000 but this 1min because it by millisecond

but what "yours" and what should i make ... i don't understand

hint:i'm will use it in ASP.net with VB

eng7asebat
Newbie Poster
6 posts since May 2010
Reputation Points: 10
Solved Threads: 0
 

do you want run a job at after 1 hour from now? it's ok?
for example now is 10:32 am
so you must have a jobtime equal with now+1 hour
so
JobTime=11:30 am
Ok
now you need a timer with interval 1000 (1 s) or 30000 (30s) in timer event
you must check if now bigger or equal Jobtime do your commands.
if Now>= JobTime and JobTime<>0 then
Call Job1 'its your job sub
JonTime=0
end if
that's it.

omoridi
Junior Poster in Training
72 posts since Sep 2009
Reputation Points: 10
Solved Threads: 10
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: