hihi,
Does anyone have timer source code in vb6??
Or where can I find it??
ThanK YoU.
Printable View
hihi,
Does anyone have timer source code in vb6??
Or where can I find it??
ThanK YoU.
Mayby this might work for you.
you can change the Timer1.Interval to make it count faster or slowerVB Code:
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
and the Label1.Caption you can change for however many seconds you want. Where the MsgBox is put what code you want to happen when that time limit is up.
Is there a way to use the same logic built in LABEL1.CAPTION but not to be displayed, I mean a timer running in the background?
Thanks
Off course it is. Timer can do anything, even nothing :) For example:
Everytime Timer1 triggers (depends of an interval), i will increase for 1. Is this what you've asked?VB Code:
int i; Private Sub Timer1_Timer() i=i+1 End Sub
in the Label1.Caption = "100" example in this post, its a timer that will be displayed, so its a static number, can i create a static number lets say 10 hours that will start the count down till its 0 then "Do Something". but all this in the background nothing need to be displayed.
or count till 10 doesn't have to be a count down. as long as it cover the number of hours that I am looking for
When the timer fires (after the .Interval amount of time [im ms]), Private Sub Timer1_Timer() runs. Do whatever you want in that sub - decrement a number, display something - it's up to you. Displaying something isn't required if you don't want a display.
I am working on a tool that have two fuctions that counts on Timer, the first one after 60 minutes will call NotePad, but this will be triggered when the user click on the Button, and the second function is a timer that will call another EXE after 10 hours without the interaction of the user.
What am I doing wrong here:
VB Code:
Private Sub Form_Load() Timer1.Interval = 100 'fire timer Timer1.Enabled = True Timer1.Interval = 60000 '1 minute End Sub Private Sub Timer1_Timer() Static iCounter As Long Static countdown As Long If iCounter = 1 Then SetWindowPos Me.hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOACTIVATE Or SWP_SHOWWINDOW Or SWP_NOMOVE Or SWP_NOSIZE Me.WindowState = vbNormal Shell "notepad" lCounter = 0 End If iCounter = iCounter + 1 If countdown = 2 Then Timer1.Enabled = False Shell "calc" Else countdown = countdown + 1 End If End sub
right now evertime the first function that is the icounter starts, it calls the second one "Countdown", the countdown works well by itself when the tool stay running for the whatever the time its ment to start after its time is up, but when I call the first function that is iCounter which will call another EXE after 60 minutes it starts and it call the second CALC (Countdown) that its not supposed to. What am I doing wrong here?
thanks
Note: I want the CALC to start only after 10 hours
in timer...
VB Code:
If countdown=600 Then '600 minutes equals 10 hours 'execution Else countdown=countdown+1 End Sub
Still have the same problem. and now the COUNTDOWN after one minute it opens hundreds of CALC. there I need to know how not to relate the two functions from each other, when the first function thats is the iCounter starts after the user click on the BUTTON it fires NOTEPAD and it calls COUNTDOWN calc. it shouldn't do that. those two are not related it should not call the second function.
VB Code:
Private Sub Form_Load() Timer1.Interval = 100 'fire timer Timer1.Enabled = True Timer1.Interval = 60000 '1 minute End Sub Private Sub Timer1_Timer() Static iCounter As Long Static countdown As Long If iCounter = 60 Then SetWindowPos Me.hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOACTIVATE Or SWP_SHOWWINDOW Or SWP_NOMOVE Or SWP_NOSIZE Me.WindowState = vbNormal Shell "notepad" lCounter = 0 End If iCounter = iCounter + 1 If countdown = 600 Then '600 minutes equals 10 hours Shell "calc" Else countdown = countdown + 1 End If End Sub
You've given a perfect example of why you should always use OPTION EXPLICIT.
VB Code:
Private Sub Form_Load() Timer1.Interval = 100 'fire timer Timer1.Enabled = True Timer1.Interval = 60000 '1 minute End Sub Private Sub Timer1_Timer() Static iCounter As Long Static countdown As Long If iCounter = 60 Then SetWindowPos Me.hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOACTIVATE Or SWP_SHOWWINDOW Or SWP_NOMOVE Or SWP_NOSIZE Me.WindowState = vbNormal Shell "notepad" lCounter = 0 ' [HL="#FFFF80"]Should be iCounter[/HL] End If iCounter = iCounter + 1 If countdown = 600 Then '600 minutes equals 10 hours Shell "calc" Else countdown = countdown + 1 End If End Sub
Two things I have to note.
Number one being, LOL. I've never gotten C and VB confused like so :p
Number two being. Make sure you post proper working code. Marty seems to read through every line of every post here :pQuote:
Originally Posted by gavio
chem
OK ,here is what I have now,
VB Code:
Private Sub Form_Load() ' Timer1.Interval = 100 'fire timer Timer1.Enabled = True Timer1.Interval = 60000 '1 minute End Sub Private Sub Timer1_Timer() Static iCounter As Long Static countdown As Long If iCounter = 1000 Then SetWindowPos Me.hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOACTIVATE Or SWP_SHOWWINDOW Or SWP_NOMOVE Or SWP_NOSIZE Me.WindowState = vbNormal iCounter = 0 End If iCounter = iCounter + 1 If countdown = 2000 Then '600 minutes equals 10 hours Shell "calc" Else countdown = countdown + 1 End If End Sub
I used the timers as 1000 and 2000 so that I can shorter time to test. Now when the 1000 start its OK, when the 2000 timer kicks in, the I get tons of calc opening on my desktop. is there a way to make it open only one CALC, it seems its going into loops with now ending.
All you need to do is to set Timer1.Enabled = False after the call to Calc.
that will do it, and it will stop the iCounter too. Thanks I think my issue is fixed, thanks again
Now that we've helped you, you can help us by pulling down the Thread Tools menu and clicking the Mark Thread Resolved button which will let everyone know that you have your answer.