Hay Sorry one more Question about timer I hope this one is last hehe:) my Qaustion is I want to use 20 Stop watches in my Form for this purpose should I Creat 20 timer and Write Code for Each one or there is some alternate way
Printable View
Hay Sorry one more Question about timer I hope this one is last hehe:) my Qaustion is I want to use 20 Stop watches in my Form for this purpose should I Creat 20 timer and Write Code for Each one or there is some alternate way
You can use a control array. Add a timer to the form, press ctrl+c ctrl+v and respond yes to the messagebox. Now you will see that each timer has the same name, just a different index. When you double click your timer, you will see that in the event, the index returns. This way you know which timer exactly fired. If you also create a control array of labels and buttons, you can use the correspomding indexes (like when pressing command1(7) will start timer1(7), and timer1(7) will update label1(7).
Hope this makes sence
Tom Cannaerts
[email protected]
Programming today is a race between software engineers striving to build bigger and better idot-proof programs, and the universe trying to produce bigger and better idiots. So far, the universe is winning -- Rich Cook
ok Logic is Good but I need to run 20 timers at differennt time .... when i press comand one I should get time of timer 1 when i press 2 i should get time of timer 2 and timer 1 and 2 are diiff from each other
Can U do one Favour just copy paste the code for me bcz iam confuse in Indexing how should I write code for timer2 ?
Try to understand the code below:
Form1 consists of:
1. Timer control: named TimerCtrl: indexed 1,2,3
2. Command button: named CommandCtrl: indexed 1,2,3
3. Label control: named LabelCtrl: indexed 1,2,3
private Sub Form_Load()
' init controls
dim nInd as Integer
for nInd = 0 to 2
LabelCtrl(nInd).Caption = "0"
CommandCtrl(nInd).Caption = "&Start Timer"
TimerCtrl(nInd).Enabled = false
TimerCtrl(nInd).Interval = (nInd+5) * (1000)
next nInd
End Sub
private Sub CommandCtrl_Click(Index as Integer)
' the command button index corresponds to the timer control index
if (TimerCtrl(Index).Enabled) then
' disable the timer
TimerCtrl(Index).Enabled = false
CommandCtrl(Index).Caption = "&Start Timer"
else
' start the timer
LabelCtrl(Index).Caption = "0"
TimerCtrl(Index).Enabled = true
CommandCtrl(Index).Caption = "&Stop Timer"
end if
End Sub
private Sub TimerCtrl_Click(Index as Integer)
' add 1 to the appropriate label
LabelCtrl(Index).Caption = CInt(LabelCtrl(Index).Caption) + 1
End Sub
Hope that you can figure out what the code does.
-Cool Bizs