Results 1 to 6 of 6

Thread: Delay help needed

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Nov 2005
    Posts
    71

    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

  2. #2
    Addicted Member
    Join Date
    Mar 2007
    Posts
    200

    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!

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Nov 2005
    Posts
    71

    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

  4. #4
    Hyperactive Member Troy Lundin's Avatar
    Join Date
    May 2006
    Posts
    489

    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.

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Nov 2005
    Posts
    71

    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().....

  6. #6
    PowerPoster VBDT's Avatar
    Join Date
    Sep 2005
    Location
    CA - USA
    Posts
    2,922

    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:
    1. Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
    2.         Static x As Integer
    3.         If x = 1 Then
    4.             textbox1.text = "Hello"
    5.         ElseIf x = 2 Then
    6.             textbox1.text = "bye"
    7.         ElseIf x = 3 Then
    8.             textbox1.text = "yay"
    9.         End If
    10.         If x < 3 Then
    11.             x += 1
    12.         Else
    13.             'Stop the Timer
    14.             x = 0
    15.             Me.Timer1.Enabled = False
    16.         End If
    17.  
    18.     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
  •  



Click Here to Expand Forum to Full Width