Results 1 to 7 of 7

Thread: loop in the timer control????

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Feb 2000
    Location
    Netherlands
    Posts
    27

    Thumbs down

    Must be simple but how do I loop through the listbox and set several intervals for the same timercontrol. Here is my source:

    Private Sub Command1_Click()
    Timer1.Interval = List1.List(0)
    Timer1.Enabled = True
    End Sub

    Private Sub Form_Load()
    List1.AddItem 1000
    List1.AddItem 2000
    List1.AddItem 3000
    Timer1.Enabled = False
    End Sub

    Private Sub Timer1_Timer()
    MsgBox List1.List(0)
    timer1.interval = false
    End Sub

    The result I want to have is that after 1 second a message appears, after 2 seconds the next message appears, etc...


  2. #2
    Hyperactive Member
    Join Date
    Sep 1999
    Posts
    305
    Try this:

    [code]
    Dim x
    Private Sub Command1_Click()
    Timer1.Enabled = True
    End Sub

    Private Sub Form_Load()
    x = 0
    List1.AddItem 1000
    List1.AddItem 2000
    List1.AddItem 3000
    Timer1.Enabled = False
    Timer1.Interval = 1000
    End Sub

    Private Sub Timer1_Timer()
    MsgBox List1.List(x)
    x = x + 1
    Timer1.Interval = x * 1000
    End Sub
    [\code]

    It should work for you. The x*1000 means that it will be an x second interval.

    bob

  3. #3
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    Hansz:

    Close, you forgot to loop so x never grows

    Code:
    Private Sub Command1_Click()
    Timer1.Enabled = True
    End Sub
    
    Private Sub Form_Load()
    x = 0
    List1.AddItem 1000
    List1.AddItem 2000
    List1.AddItem 3000
    Timer1.Enabled = False
    Timer1.Interval = 1000
    End Sub
    
    Private Sub Timer1_Timer()
      Do
         MsgBox List1.List(x)
         x = x + 1
         Timer1.Interval = x * 1000
      Loop Until x = 3
         Timer1.Enabled = False
    
    End Sub

    [Edited by HeSaidJoe on 08-04-2000 at 06:07 PM]
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  4. #4
    Hyperactive Member
    Join Date
    Sep 1999
    Posts
    305

    eek NO!

    don't do what he said. That doesn't do what you want. His will give you a bunch of messageboxes at once, and that's bad. He does have a point on the x growing business. Change that sub to the following:

    Code:
    Private Sub Timer1_Timer()
      If x <= List1.ListCount Then
         MsgBox List1.List(x)
         x = x + 1
         Timer1.Interval = x * 1000
      Else
         Timer1.Enabled = False
         x = 0
      End If
    End Sub
    that will loop until the end of the list, making the timer interval increase by a second each time, and displaying the message box after each interval.

    bob

  5. #5
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    BULL..
    it will give you the message boxes 1 sec apart as the question asked for (and yes that, in my opinion is more than one would want). If you want more time between messages you increase the interval.

    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  6. #6

    Thread Starter
    Junior Member
    Join Date
    Feb 2000
    Location
    Netherlands
    Posts
    27

    thanx all but forgot something???

    thanx all but I don't want the value of x set to be the timer interval? The timer interval must be set by the values in the listbox.

    What will happen if I change these values??????

  7. #7

    Thread Starter
    Junior Member
    Join Date
    Feb 2000
    Location
    Netherlands
    Posts
    27

    Thanx Bob, think I have it allready

    In the source below I can use different and more or less values in the listbox, now it's complete:

    Private Sub Timer1_Timer()
    If x <= List1.ListCount - 1 Then
    Timer1.Interval = List1.List(x)
    MsgBox List1.List(x)
    x = x + 1
    Else
    Timer1.Enabled = False
    x = 0
    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
  •  



Click Here to Expand Forum to Full Width