Click to See Complete Forum and Search --> : 20 Stopwatches
sahilkhan
May 21st, 2001, 06:51 AM
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
Cakkie
May 21st, 2001, 07:07 AM
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
slisse@planetinternet.be
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
sahilkhan
May 21st, 2001, 07:44 AM
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 ?
coolbiz
May 21st, 2001, 07:58 AM
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
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.