I have a feeling that this is something thats really easy, but it is driving me crazy! I have a project that simulates a basketball game. In one quarter there are 30 match ups that take 12 seconds. I have a button that sets the tick procedure, and I tried coding it like this Dim counter as Integer = 0 Do While counter < 31 matchTimer.Enabled = True counter = counter + 1 Loop Any ideas why this wont work?
Shouldn’t you turn the timer off before the msgbox?
From: VeenaMG via visualbasic-l [mailto:visualbasic-l@groups.ittoolbox.com]
Sent: Saturday, January 24, 2009 10:45 PM
To: css nico
Subject: RE:[visualbasic-l] Timers… Do while loop
Posted by
VeenaMG
on 01/25/2009 09:18:00 AM
Hi,
What I guess is, you want the Timer to run 12 Seconds X 30 Times…
OK, Set Timer’s Interval = 12000, Make It Disable, Initially.
Declare a Form Level Variable say, Dim MyCount As Integer
In Button Click, Write This Code :
MyCount = 0
Timer1.Enabled = True
In Timer1_Timer Event, write this Code :
MyCount = MyCount +1
If MyCount >= 30 Then
MsgBox “Time-Up…”
MyCount = 0
Timer1.Enabled = False
End If
Regards
Veena
Hi,
Maybe your timer has not been started : matchtimer.start()
roughly :
Drag a timer component to your form and configure the properties
Start it somewhere , in the formload or with a button event …
connect a event handler to your timer,(doubleclick your timer on form)
'-----------------------------------------------------------------------------------
Private Sub MainForm_Load(
…
my100msTimer.Start()
…
end sub
Sub my100msTimer_Elapsed( …snip … ) Handles my100msTimer.Elapsed
…
If countdown1 Then countdown1 -= 1
If countdown2 Then countdown2 -= 1
…
End Sub
now you have a timer running in the background that counts down the two var?s to zero.
so fill countdown1 = 120 ’ equals 12 seconds ? 100ms
and test if for being zero anywhere in you code.
'-----------------------------------------------------------------------------------
Also note there are two types of Timers components, a ‘system.windows.forms’ and a ‘system.timers’ The ‘forms’ one is less accurate.
Making a clock based on timers is a risky idea.
Hi,
What I guess is, you want the Timer to run 12 Seconds X 30 Times…
OK, Set Timer’s Interval = 12000, Make It Disable, Initially.
Declare a Form Level Variable say, Dim MyCount As Integer
In Button Click, Write This Code :
MyCount = 0
Timer1.Enabled = True
In Timer1_Timer Event, write this Code :
MyCount = MyCount +1
If MyCount >= 30 Then
MsgBox “Time-Up…”
MyCount = 0
Timer1.Enabled = False
End If
Regards
Veena
Why are you enabling your matchtimer inside the Do Loop? You are enabling this matchtimer 31 times in about a hundredth of a second. Usually you establish a Do Loop because you are waiting for a condition to happen. If you want to loop 31 times, use a For Next loop. Also, during this 31 loops, nothing else will be updated without a DoEvents statment inside the loop. I dono’t know what you are doing, but you are doing it poorly.
What do you mean it doesn’t work? Is it throwing an error? Is it not
setting matchtimer? Does the smoke leak out of the computer when you run
this?
John Warner
From: aligatorfurr via visualbasic-l
[mailto:visualbasic-l@Groups.ITtoolbox.com]
Sent: Friday, January 23, 2009 9:03 PM
To: john
Subject: [visualbasic-l] Timers… Do while loop
I have a feeling that this is something thats really easy, but it is
driving me crazy!
I have a project that simulates a basketball game. In one quarter there
are 30 match ups that take 12 seconds.
I have a button that sets the tick procedure, and I tried coding it like
this
Dim counter as Integer = 0
Do While counter < 31
matchTimer.Enabled = True
counter = counter + 1
Loop
Any ideas why this wont work?