|
-
May 6th, 2006, 10:54 PM
#1
Thread Starter
Junior Member
source code for timer
hihi,
Does anyone have timer source code in vb6??
Or where can I find it??
ThanK YoU.
-
May 6th, 2006, 11:06 PM
#2
Hyperactive Member
Re: source code for timer
Mayby this might work for you.
VB 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
you can change the Timer1.Interval to make it count faster or slower
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.
-
Aug 29th, 2006, 09:02 AM
#3
Hyperactive Member
Re: source code for timer
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
-
Aug 29th, 2006, 09:07 AM
#4
Re: source code for timer
Off course it is. Timer can do anything, even nothing For example:
VB Code:
int i;
Private Sub Timer1_Timer()
i=i+1
End Sub
Everytime Timer1 triggers (depends of an interval), i will increase for 1. Is this what you've asked?
-
Aug 29th, 2006, 09:13 AM
#5
Hyperactive Member
Re: source code for timer
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.
-
Aug 29th, 2006, 09:15 AM
#6
Hyperactive Member
Re: source code for timer
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
-
Aug 29th, 2006, 09:27 AM
#7
Re: source code for timer
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.
The most difficult part of developing a program is understanding the problem.
The second most difficult part is deciding how you're going to solve the problem.
Actually writing the program (translating your solution into some computer language) is the easiest part.
Please indent your code and use [HIGHLIGHT="VB"] [/HIGHLIGHT] tags around it to make it easier to read.
Please Help Us To Save Ana
-
Aug 29th, 2006, 10:00 AM
#8
Hyperactive Member
Re: source code for timer
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
-
Aug 29th, 2006, 10:06 AM
#9
Hyperactive Member
Re: source code for timer
Note: I want the CALC to start only after 10 hours
-
Aug 29th, 2006, 10:19 AM
#10
Re: source code for timer
in timer...
VB Code:
If countdown=600 Then '600 minutes equals 10 hours
'execution
Else
countdown=countdown+1
End Sub
-
Aug 29th, 2006, 11:00 AM
#11
Hyperactive Member
Re: source code for timer
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
-
Aug 29th, 2006, 11:09 AM
#12
Re: source code for timer
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
-
Aug 29th, 2006, 11:38 AM
#13
Re: source code for timer
Two things I have to note.
Number one being, LOL. I've never gotten C and VB confused like so 
 Originally Posted by gavio
Off course it is. Timer can do anything, even nothing  For example:
VB Code:
[b]int i;[/b]
Private Sub Timer1_Timer()
i=i+1
End Sub
Everytime Timer1 triggers (depends of an interval), i will increase for 1. Is this what you've asked?
Number two being. Make sure you post proper working code. Marty seems to read through every line of every post here 
chem
Visual Studio 6, Visual Studio.NET 2005, MASM
-
Aug 29th, 2006, 12:21 PM
#14
Hyperactive Member
Re: source code for timer
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.
-
Aug 29th, 2006, 12:25 PM
#15
Re: source code for timer
All you need to do is to set Timer1.Enabled = False after the call to Calc.
-
Aug 29th, 2006, 12:36 PM
#16
Hyperactive Member
Re: source code for timer
that will do it, and it will stop the iCounter too. Thanks I think my issue is fixed, thanks again
-
Aug 29th, 2006, 12:37 PM
#17
Re: source code for timer
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|