|
-
Jul 10th, 2006, 07:46 AM
#1
Thread Starter
Frenzied Member
multiple timers, error
VB Code:
Dim t(5) As Timer
Private Sub Form_Load()
t(0).Interval = 5000
t(0).Enabled = True
End Sub
Private Sub t_Timer(numb As Integer)
MsgBox "timer for " & t & "is finished."
End Sub
how do i correct this code?
it says with block variable not set for the
t(0).Interval = 5000
-
Jul 10th, 2006, 07:53 AM
#2
Frenzied Member
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
-
Jul 10th, 2006, 08:20 AM
#3
Thread Starter
Frenzied Member
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.
-
Jul 10th, 2006, 11:40 AM
#4
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:
Dim t(5) As Timer
Private Sub Form_Load()
Dim i As Long
For i = 0 To 5
timer(i) = Me.Controls.Add("VB.Timer", "timer_" & CStr(i))
Next i
...
-
Jul 12th, 2006, 01:35 AM
#5
Frenzied Member
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:
The Click event procedure is shared by all the option buttons:
VB Code:
Private Sub optButton_Click (Index As Integer)
picDisplay.BackColor = QBColor(Index + 1)
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:
Private Sub cmdAdd_Click ()
If MaxId = 0 Then MaxId = 1 ' Set total option
' buttons.
If MaxId > 8 Then Exit Sub ' Only ten buttons
' allowed.
MaxId = MaxId + 1 ' Increment button count.
Load optButton(MaxId) ' Create new button.
optButton(0).SetFocus ' Reset button selection.
' Set new button under previous button.
optButton(MaxId).Top = optButton(MaxId - 1)._
Top + 400
optButton(MaxId).Visible = True ' Display new
' button.
optButton(MaxId).Caption = "Option" & MaxId + 1
End Sub
Option buttons are removed by the Click event procedure for the Delete command button:
VB Code:
Private Sub cmdDelete_Click ()
If MaxId <= 1 Then Exit Sub ' Keep first two
' buttons.
Unload optButton(MaxId) ' Delete last button.
MaxId = MaxId - 1 ' Decrement button count.
optButton(0).SetFocus ' Reset button selection.
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
|