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:

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.

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:

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

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?

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

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.

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.

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....

Edited 3 Years Ago by mike_2000_17: Fixed formatting

Comments
Do your own homework, or at least post your best effort

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

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

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.

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
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

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.

if you want to use in asp.net
you must check in every post back
or create ajaxtimer to refresh your page every 1 minute

i have test online web site . ok!
i need make a timer when user statr the exam tne timer is 00:00:00
and then start begin to one hour when this hour left the page closed
and the session closed

i don't know what can i do this

can you help me plz?

ok
you must ask in asp.net
but
u must create a session with ur timer
u must set session("timer") with ur time like severe time + 1h
then in every page u must creat a javascript timer
a pass timer session
after that when timer finished u must postback
when u post back
in postback u can check every thing u want in code
like close session and everything.

hi im astine i just want to know how to make a score in a quiz with a timer??

@Astine, You need to open your own thread. We will answer from there. It is not allowed to "hijack" other OP's threads.:)

In your question, be specific on what you need to achieve so we can help you out much quicker.

Click HERE to start your own thread.

Hi, I use the second code in VB6

Private Sub Command3_Click()
     Timer1.Interval = 1000
     Label7.Caption = "80"
End Sub

Private Sub Timer1_Timer()
     If Label1.Caption = 0 Then
          MsgBox ("MSG HERE")
          Label1.Caption = 80
          Timer1.Enabled = False
     Else
          Label1.Caption = Label1.Caption - 1
     End If
End Sub

When I click again after its end and closed the msgbox, the timer dont start again, why? Only start again if I click bofore the end.
And how I can do to the msgbox appear on top of all programs I'm running?
Thanks

This article has been dead for over six months. Start a new discussion instead.