|
-
May 2nd, 2001, 09:29 AM
#1
Thread Starter
Registered User
Timer
Hello,
I need to put a timer into an app that counts down from from xx amount of seconds. Can this be done? I'm just learning this stuff as I go.
Thanks,
Gabe
[email protected]
-
May 2nd, 2001, 09:41 AM
#2
Fanatic Member
I threw this together. Is it what you are looking for ?
Place a timer control, label, textBox, and commandButton on the form. Then just paste the code below into your form. Enter the number of seconds into the textbox, click the command button, and the timer will count backwards to zero and display the results in the label.
Code:
Option Explicit
Private Sub Command1_Click()
Label1.Caption = Text1.Text
Timer1.Enabled = True
End Sub
Private Sub Form_Load()
Timer1.Interval = 1000
Timer1.Enabled = False
End Sub
Private Sub Timer1_Timer()
Label1.Caption = Label1.Caption - 1
If Label1.Caption = 0 Then
Timer1.Enabled = False
End If
End Sub
-
May 2nd, 2001, 09:42 AM
#3
Addicted Member
Well, if you put a timer on the form and then just set the timer interval to 1 second and then have a counter loop just to count down each time the timer restarts. Maybe like this :
timer1.interval = ???
let x=10
then in the timer1 code :
let x=x-1
if x = 0 then ?????
then code to restart timer and it will countdown until 0, I think!
I can do the code, if you want it - hope this helps
-
May 2nd, 2001, 09:42 AM
#4
Put a normal timer control on your form, set it's interval to the amout of seconds you wan't and enable it.
It will then raise an event, when en xx seconds has passed. On the event just disable it.
The timer control however has some limitations, so if it is a long time, that you wan't counted down, you will need to use the timers lying inside windows.
-
May 2nd, 2001, 09:44 AM
#5
_______
<?>
or...
Code:
Private Sub Form_Load()
Timer1.Enabled = True
Timer1.Interval = 1000 'approx 1 second
End Sub
Private Sub Timer1_Timer()
Dim iCount As Integer
Static x As Integer
iCount = 10
If x >= 1 Then
iCount = 10 - x
End If
Print iCount
x = x + 1
If iCount = 0 Then MsgBox "10 seconds"
End Sub
"A myth is not the succession of individual images,
but an integerated meaningful entity,
reflecting a distinct aspect of the real world."
___ Adolf Jensen
-
May 2nd, 2001, 09:46 AM
#6
Thread Starter
Registered User
Sweet. That should do it. Thanks.
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
|