Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

Timer Help

Hello, I'm using a Timer control to repeat a process but the time is variable from 0 to 180 seconds.I'm using a VScrollBar to control the time. The timer control's max value is 65,535 milliseconds, so I wrote:

Private Sub tmrMuestreo1_Timer()
tmrMuestreo1.Enabled = True

If vsbNum.Value <= 60 Then
tmrMuestreo1.Interval = Str(vsbNum.Value) * 1000
Call GetImage
End If

If vsbNum.Value > 60 Then
tmrMuestreo1.Interval = 60000
GetImage
Call tmrMuestreo2_Timer
If vsbNum.Value < 121 Then
Call tmrMuestreo2_Timer
Call GetImage
End If
End If
End Sub

Private Sub tmrMuestreo2_Timer()
tmrMuestreo2.Enabled = True
tmrMuestreo2.Interval = (vsbNum.Value - 60) * 1000
End Sub

But it doesn't work, if the vsbNum Value is grater than 60, the process is repeated just in 60 seconds.
Can some help me?
[1007 byte] By [mechis] at [2007-11-11 7:20:11]
# 1 Re: Timer Help
I would use only one Timer control, and a global variable to set the number of seconds.
To set the Timer:

private m_delay as long

m_delay = vsbNum.Value
'' limit the interval to 1 minute
myTimer.Interval = iif(m_delay > 60, 60000, 1000 * m_delay)
myTimer.Enabled = true

and in the Timer event:

myTimer_Timer()
myTimer.enabled = false
if m_delay > 60 then
'' just decrease the delay and restart the timer
m_delay = m_delay - 60
myTimer.Interval = iif(m_delay > 60, 60000, 1000*m_delay)
myTimer.Enabled = true
else
''' do the timer operation here
endif

Marco
mstraf at 2007-11-11 17:27:10 >
# 2 Re: Timer Help
Thanks mstraf, but I have some problems with this code, if vsbNum.Value is grater than 60 the process repeats 60 second later and later every (vsbNUm.Value - 60) seconds.

Any Help?
mechis at 2007-11-11 17:28:10 >
# 3 Re: Timer Help
please post your code
Marco
mstraf at 2007-11-11 17:29:10 >
# 4 Re: Timer Help
The code is:

Dim m_delay as long

cmdStar_click()
m_delay = vsbNum.Value
myTimer.Interval = iif(m_delay > 60, 60000, 1000 * m_delay)
myTimer.Enabled = true
end sub

and in the Timer event:

myTimer_Timer()
if m_delay > 60 then
m_delay = m_delay - 60
myTimer.Interval = iif(m_delay > 60, 60000, 1000*m_delay)
myTimer.Enabled = true
else
GetImage
Endif

Thanks for your answer
mechis at 2007-11-11 17:30:05 >
# 5 Re: Timer Help
You did not disable the Timer in the timer event
BTW "Private Sub" was missing from your code?!?

Marco

code tested:

Dim m_delay As Long

Private Sub cmdStart_Click()
m_delay = vsbNum.Value
myTimer.Interval = IIf(m_delay > 60, 60000, 1000 * m_delay)
myTimer.Enabled = True
End Sub

Private Sub myTimer_Timer()
myTimer.Enabled = False
If m_delay > 60 Then
m_delay = m_delay - 60
myTimer.Interval = IIf(m_delay > 60, 60000, 1000 * m_delay)
myTimer.Enabled = True
Else
GetImage
End If
End Sub
mstraf at 2007-11-11 17:31:14 >
# 6 Re: Timer Help
Thanks a lot mstraf I corrected my mistake, but I need the process to be repeated all the time, and this code just repeat it once.

What can I do about it?
THANKS
mechis at 2007-11-11 17:32:10 >
# 7 Re: Timer Help
In the timer event, after the GetImage statement set again the timer calling cmdStart_Click
Marco
mstraf at 2007-11-11 17:33:14 >