|
-
Jul 18th, 2001, 02:08 AM
#1
Thread Starter
Member
delay loop
hey, im quite new to visual basic so i dont know much. i was wondering how do i make a delay loop, for example like a countdown, like i click a button and it displays 1 to 10, one second a number( like 10, then it waits a seccond, 9, waits another second and so on) and when it reaches 0 more text appears or a new form opens up and stuff like that.
Thanx
 WoG_sTyLe_69 
-
Jul 18th, 2001, 02:19 AM
#2
-= B u g S l a y e r =-
try this ...
Start a new project,
add a command button and paste the code below into the form.
Code:
Option Explicit
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Private Sub Command1_Click()
Dim i As Integer
For i = 10 To 1 Step -1
Label1.Caption = i
DoEvents
Sleep 1000
Next i
End Sub
-
Jul 18th, 2001, 02:25 AM
#3
PowerPoster
Hi
You can use a timer control for this purpose. Add one to ur form and set its interval property to 1000. Best to set timers as 'disabled' until u use. Enabled = False
Timers are not quite as accurate as atomic clocks or even egg timers but they are good enuf for ur purpose.
Form-------------------------
Dim countdown as integer
private sub command1_click
countdown = 10
timer1.enabled = true
command1.enabled = false 'prevent double firing
end sub
private sub timer1_timer
label1.caption = countdown
countdown = countdown -1
if countdown <= 0 then
timer1.enabled = false 'good idea to turn timers off
command1.enabled = true
'Process other stuff u want to show
end if
end sub
-----------------------------
Regards
Stuart
http://www.gstsmartbook.com
-
Jul 18th, 2001, 02:29 AM
#4
PowerPoster
Sorry Pete, just wanted to add a word of warning for wog style on using sleep function. Would make no diff in this simple program but is not a good idea to tie up processor in more complicated programs.
Regards
Stuart
http://www.gstsmartbook.com
-
Jul 18th, 2001, 02:32 AM
#5
-= B u g S l a y e r =-
beachbum, no problem, I do agree.... I wasn't aware of the fact that it tied up the processor.. well I am now
-
Jul 18th, 2001, 02:42 AM
#6
Hyperactive Member
or you could do this
VB Code:
Private Sub Form_Load()
Label1.Caption = 10
Timer1.Interval = 1000
End Sub
Private Sub Timer1_Timer()
Label1.Caption = Label1.Caption - 1
Me.Refresh
If Label1.Caption = 0 Then
Label1.Caption = "WOW"
Timer1.Enabled = False
End If
End Sub
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
|