|
-
Jun 9th, 2007, 10:45 PM
#1
Thread Starter
Lively Member
Delay help needed
ok lets say i have a list of objects that i want to put in lets say the list look like this.
hello
bye
yay
lol
john
although lets say the first one had to go into a the textbox after 1 second and the 2 had to go in after 3 second and the thrid after 2 seconds, and so on....
is there i way i can do something like
textbox1.text = "hello"
delay 2 sec
textbox1.text = "bye"
delay 3 sec
textbox1.text = "yay"
thank you for your time/help
-
Jun 9th, 2007, 11:15 PM
#2
Addicted Member
Re: Delay help needed
do u know how timer works?
ill give u a basic idea and then im sure ull be able to figure out the rest
once u create a timer and start it with 'Timer1.start()' it will do the spicified actions under a timer.tick sub, such will be automatically creates if u double click on ur timer.
Under the timer properties, you'll see interval, which means how much delay between each "Tick"
Heres an example:
'create a timer in ur design called timer1
in ur form.load type: "Timer1.start()"
Code:
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Static x As Integer
If x = 1 Then
textbox1.text = "Hello"
ElseIf x = 2 Then
textbox1.text = "bye"
ElseIf x = 3 Then
textbox1.text = "yay"
End If
x += 1
End Sub
Hope that helps!
-
Jun 9th, 2007, 11:20 PM
#3
Thread Starter
Lively Member
Re: Delay help needed
I found a different way
textbox1.text = "hello"
Threading.Thread.Sleep(2000)
textbox1.text = "bye"
Threading.Thread.Sleep(3000)
and so on
than you all for the help
-
Jun 10th, 2007, 12:23 AM
#4
Hyperactive Member
Re: Delay help needed
Threading.Thread.Sleep(3000)
That method is not recommended. If used on your UI thread your program will freeze. I would go with the timer method as it creates it uses it's own thread.
Prefix has no suffix, but suffix has a prefix.
-
Jun 10th, 2007, 01:33 AM
#5
Thread Starter
Lively Member
Re: Delay help needed
ah i noticed lol but i'm try'n to avoid a timer maybe if it's possible to have multiple timers that have different timespans in them like maybe
Code:
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
timer1.interval = 2000
end sub
multiple timers that have different timespans in them like maybe
Code:
Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
timer2.interval = 3000
end sub
then like
Code:
textbox1.text
timer1()
textbox1.text
timer2().....
-
Jun 10th, 2007, 01:43 AM
#6
Re: Delay help needed
I don't get it you say you want to avoid Timer but then you say you want multiple Timers for the job. Why use multiple Timers if you can use one. The Zapper's example will do the jub with a small addition:
vb Code:
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Static x As Integer
If x = 1 Then
textbox1.text = "Hello"
ElseIf x = 2 Then
textbox1.text = "bye"
ElseIf x = 3 Then
textbox1.text = "yay"
End If
If x < 3 Then
x += 1
Else
'Stop the Timer
x = 0
Me.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
|