Results 1 to 5 of 5

Thread: multiple timers, error

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Sep 2005
    Posts
    1,364

    multiple timers, error

    VB Code:
    1. Dim t(5) As Timer
    2.  
    3. Private Sub Form_Load()
    4.     t(0).Interval = 5000
    5.     t(0).Enabled = True
    6. End Sub
    7.  
    8. Private Sub t_Timer(numb As Integer)
    9.     MsgBox "timer for " & t & "is finished."
    10. End Sub

    how do i correct this code?

    it says with block variable not set for the

    t(0).Interval = 5000

  2. #2
    Frenzied Member
    Join Date
    May 2003
    Location
    Sydney
    Posts
    1,123

    Re: multiple timers, error

    this is a logical error. u have declared t(5) to be 6 instances of timer control but u have never actually created the instance for the timer. one way u can do it is put a timer in the form and set the index property to 0. then u can load the timers by using
    VB Code:
    1. Load t(1)

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Sep 2005
    Posts
    1,364

    Re: multiple timers, error

    thanks how would i then unload t(1)?

    Set t(Index) = Nothing

    gives me invalid use of object property or something

    and also

    Load t(1)

    how would i make that so its like

    If t(1) <> Loaded Then Load t(1)
    Last edited by Pouncer; Jul 10th, 2006 at 08:36 AM.

  4. #4
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: multiple timers, error

    You cannot dynamically create Timer controls and restrict them to the code alone. Timer is not a class, it is a Control, the only way you can create one is to add it to the form.

    VB Code:
    1. Dim t(5) As Timer
    2.  
    3. Private Sub Form_Load()
    4.   Dim i As Long
    5.   For i = 0 To 5
    6.     timer(i) = Me.Controls.Add("VB.Timer", "timer_" & CStr(i))
    7.   Next i
    8.  
    9.   ...

  5. #5
    Frenzied Member
    Join Date
    May 2003
    Location
    Sydney
    Posts
    1,123

    Re: multiple timers, error

    from msdn on control array
    Events in the Control Array Application
    Next, you need to add the event procedures for the option buttons and command buttons. Start by adding the form declaration:
    VB Code:
    1. Dim MaxId As Integer

    The Click event procedure is shared by all the option buttons:
    VB Code:
    1. Private Sub optButton_Click (Index As Integer)
    2.    picDisplay.BackColor = QBColor(Index + 1)
    3. End Sub

    New option buttons are added by the Click event procedure for the Add command button. In this example, the code checks that no more than ten option buttons are loaded before the Load statement is executed. Once a control is loaded, its Visible property must be set to True.
    VB Code:
    1. Private Sub cmdAdd_Click ()
    2.    If MaxId = 0 Then MaxId = 1   ' Set total option
    3.                                  ' buttons.
    4.    If MaxId > 8 Then Exit Sub   ' Only ten buttons
    5.                                  ' allowed.
    6.    MaxId = MaxId + 1         ' Increment button count.
    7.    Load optButton(MaxId)      ' Create new button.
    8.    optButton(0).SetFocus      ' Reset button selection.
    9.    ' Set new button under previous button.
    10.    optButton(MaxId).Top = optButton(MaxId - 1)._
    11.    Top + 400
    12.    optButton(MaxId).Visible = True   ' Display new
    13.                                  ' button.
    14.    optButton(MaxId).Caption = "Option" & MaxId + 1
    15. End Sub

    Option buttons are removed by the Click event procedure for the Delete command button:
    VB Code:
    1. Private Sub cmdDelete_Click ()
    2.    If MaxId <= 1 Then Exit Sub   ' Keep first two
    3.                                  ' buttons.
    4.    Unload optButton(MaxId)      ' Delete last button.
    5.    MaxId = MaxId - 1            ' Decrement button count.
    6.    optButton(0).SetFocus      ' Reset button selection.
    7. 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