Using timers  
Author Message
Realitygdk





PostPosted: Sat Feb 04 10:56:00 CST 2006 Top

Visual Basic >> Using timers Hello,
1.
Is there any 'optimal' number of timers can be used on one form?
2.
Which design will be more efficient:
A. using one timer and combine different events using If... Then
statements.
Because each event requires different time interval change timer
intervals for each event will be included in the code
or
B.
For each event use different timer with preset time interval

Your thoughts please,
Jack

Visual Studio247  
 
 
Michael





PostPosted: Sat Feb 04 10:56:00 CST 2006 Top

Visual Basic >> Using timers I have always run multiple timers in this situation. Name the timers so
that the timer_Elapsed events are obvious. This will make you code more
readable.

Mike Ober.

"Jack" <replyTo@newsgroup> wrote in message
news:OJ$EMail@HideDomain.com...
> Hello,
> 1.
> Is there any 'optimal' number of timers can be used on one form?
> 2.
> Which design will be more efficient:
> A. using one timer and combine different events using If... Then
> statements.
> Because each event requires different time interval change timer
> intervals for each event will be included in the code
> or
> B.
> For each event use different timer with preset time interval
>
> Your thoughts please,
> Jack
>
>
>



 
 
Veign





PostPosted: Sat Feb 04 10:54:18 CST 2006 Top

Visual Basic >> Using timers What are you trying to do?

Option:
One timer with a low interval (1 second maybe) and have the timer event
check for how much time has passed and react accordingly. Then your timer
event can trigger several events based on passed time.

Remember timer events are low priority events with the system and instead of
checking for a time being reached you should check for a time being
passed...

--
Chris Hanscom - Microsoft MVP (VB)
Veign's Resource Center
http://www.veign.com/vrc_main.asp
Veign's Blog
http://www.veign.com/blog
--


"Jack" <replyTo@newsgroup> wrote in message
news:OJ$EMail@HideDomain.com...
> Hello,
> 1.
> Is there any 'optimal' number of timers can be used on one form?
> 2.
> Which design will be more efficient:
> A. using one timer and combine different events using If... Then
> statements.
> Because each event requires different time interval change timer
> intervals for each event will be included in the code
> or
> B.
> For each event use different timer with preset time interval
>
> Your thoughts please,
> Jack
>
>


 
 
Jack





PostPosted: Sat Feb 04 15:20:50 CST 2006 Top

Visual Basic >> Using timers Thank you.
What I am worrying about is that my form has already 15 timers on it and I
am in need to add some more.
Not all the timers are active at the same time of course, but one or two.
I do not want to have big overhead, or the code became too 'heavy'.
Jack
"Jack" <replyTo@newsgroup> wrote in message
news:OJ$EMail@HideDomain.com...
> Hello,
> 1.
> Is there any 'optimal' number of timers can be used on one form?
> 2.
> Which design will be more efficient:
> A. using one timer and combine different events using If... Then
> statements.
> Because each event requires different time interval change timer
> intervals for each event will be included in the code
> or
> B.
> For each event use different timer with preset time interval
>
> Your thoughts please,
> Jack
>
>


 
 
Veign





PostPosted: Sat Feb 04 15:23:07 CST 2006 Top

Visual Basic >> Using timers Again, I ask, what are you trying to do? By explaining what you ware doing
you may get alternate methods that will work better. When you ask a
specific question you get specific answers - as we don't how or why things
are being used...

Like, 15 timers on a form, to me, seems very excessive. I have probably
never used more than 3.....

--
Chris Hanscom - Microsoft MVP (VB)
Veign's Resource Center
http://www.veign.com/vrc_main.asp
Veign's Blog
http://www.veign.com/blog
--


"Jack" <replyTo@newsgroup> wrote in message
news:EMail@HideDomain.com...
> Thank you.
> What I am worrying about is that my form has already 15 timers on it and I
> am in need to add some more.
> Not all the timers are active at the same time of course, but one or two.
> I do not want to have big overhead, or the code became too 'heavy'.
> Jack
> "Jack" <replyTo@newsgroup> wrote in message
> news:OJ$EMail@HideDomain.com...
>> Hello,
>> 1.
>> Is there any 'optimal' number of timers can be used on one form?
>> 2.
>> Which design will be more efficient:
>> A. using one timer and combine different events using If... Then
>> statements.
>> Because each event requires different time interval change timer
>> intervals for each event will be included in the code
>> or
>> B.
>> For each event use different timer with preset time interval
>>
>> Your thoughts please,
>> Jack
>>
>>
>
>


 
 
Jack





PostPosted: Sat Feb 04 16:01:39 CST 2006 Top

Visual Basic >> Using timers It is a communication program.
timers are used for:
-main timer --> heart of the system
-retrieving TAPI callbacks
-detecting busy line
-scheduler
-recording
-playing
-running script
-finding specified window (FindWindow() )
-redirecting voice
-buffering
-monitoring

should I go on?
Jack


"Veign" <EMail@HideDomain.com> wrote in message
news:EMail@HideDomain.com...
> Again, I ask, what are you trying to do? By explaining what you ware
> doing you may get alternate methods that will work better. When you ask a
> specific question you get specific answers - as we don't how or why things
> are being used...
>
> Like, 15 timers on a form, to me, seems very excessive. I have probably
> never used more than 3.....
>
> --
> Chris Hanscom - Microsoft MVP (VB)
> Veign's Resource Center
> http://www.veign.com/vrc_main.asp
> Veign's Blog
> http://www.veign.com/blog
> --
>
>
> "Jack" <replyTo@newsgroup> wrote in message
> news:EMail@HideDomain.com...
>> Thank you.
>> What I am worrying about is that my form has already 15 timers on it and
>> I am in need to add some more.
>> Not all the timers are active at the same time of course, but one or two.
>> I do not want to have big overhead, or the code became too 'heavy'.
>> Jack
>> "Jack" <replyTo@newsgroup> wrote in message
>> news:OJ$EMail@HideDomain.com...
>>> Hello,
>>> 1.
>>> Is there any 'optimal' number of timers can be used on one form?
>>> 2.
>>> Which design will be more efficient:
>>> A. using one timer and combine different events using If... Then
>>> statements.
>>> Because each event requires different time interval change timer
>>> intervals for each event will be included in the code
>>> or
>>> B.
>>> For each event use different timer with preset time interval
>>>
>>> Your thoughts please,
>>> Jack
>>>
>>>
>>
>>
>
>


 
 
Veign





PostPosted: Sat Feb 04 16:03:56 CST 2006 Top

Visual Basic >> Using timers Good luck. You seem very hesistant to give information and when you do you
come across with an attitude. I was trying to help.

To answer your question - No, you don't need to go on....

--
Chris Hanscom - Microsoft MVP (VB)
Veign's Resource Center
http://www.veign.com/vrc_main.asp
Veign's Blog
http://www.veign.com/blog
--


"Jack" <replyTo@newsgroup> wrote in message
news:%EMail@HideDomain.com...
> It is a communication program.
> timers are used for:
> -main timer --> heart of the system
> -retrieving TAPI callbacks
> -detecting busy line
> -scheduler
> -recording
> -playing
> -running script
> -finding specified window (FindWindow() )
> -redirecting voice
> -buffering
> -monitoring
>
> should I go on?
> Jack
>
>
> "Veign" <EMail@HideDomain.com> wrote in message
> news:EMail@HideDomain.com...
>> Again, I ask, what are you trying to do? By explaining what you ware
>> doing you may get alternate methods that will work better. When you ask
>> a specific question you get specific answers - as we don't how or why
>> things are being used...
>>
>> Like, 15 timers on a form, to me, seems very excessive. I have probably
>> never used more than 3.....
>>
>> --
>> Chris Hanscom - Microsoft MVP (VB)
>> Veign's Resource Center
>> http://www.veign.com/vrc_main.asp
>> Veign's Blog
>> http://www.veign.com/blog
>> --
>>
>>
>> "Jack" <replyTo@newsgroup> wrote in message
>> news:EMail@HideDomain.com...
>>> Thank you.
>>> What I am worrying about is that my form has already 15 timers on it and
>>> I am in need to add some more.
>>> Not all the timers are active at the same time of course, but one or
>>> two.
>>> I do not want to have big overhead, or the code became too 'heavy'.
>>> Jack
>>> "Jack" <replyTo@newsgroup> wrote in message
>>> news:OJ$EMail@HideDomain.com...
>>>> Hello,
>>>> 1.
>>>> Is there any 'optimal' number of timers can be used on one form?
>>>> 2.
>>>> Which design will be more efficient:
>>>> A. using one timer and combine different events using If... Then
>>>> statements.
>>>> Because each event requires different time interval change timer
>>>> intervals for each event will be included in the code
>>>> or
>>>> B.
>>>> For each event use different timer with preset time interval
>>>>
>>>> Your thoughts please,
>>>> Jack
>>>>
>>>>
>>>
>>>
>>
>>
>
>


 
 
Jack





PostPosted: Sat Feb 04 16:19:11 CST 2006 Top

Visual Basic >> Using timers No need to get offended. If you are, I apologize.
I have just tried to answer your question.
You asked me what I am trying to do and I explained.
Each timer has specific task as shown. At most only one or two timers are
active at the same time.
What I am trying to find is how that timers are weighting on my code?
Is there a better approach to reduce number of timers and cumulate more code
inside them?
It was my original question, btw,
Jack

"Veign" <EMail@HideDomain.com> wrote in message
news:enwL%EMail@HideDomain.com...
> Good luck. You seem very hesistant to give information and when you do
> you come across with an attitude. I was trying to help.
>
> To answer your question - No, you don't need to go on....
>
> --
> Chris Hanscom - Microsoft MVP (VB)
> Veign's Resource Center
> http://www.veign.com/vrc_main.asp
> Veign's Blog
> http://www.veign.com/blog
> --
>
>
> "Jack" <replyTo@newsgroup> wrote in message
> news:%EMail@HideDomain.com...
>> It is a communication program.
>> timers are used for:
>> -main timer --> heart of the system
>> -retrieving TAPI callbacks
>> -detecting busy line
>> -scheduler
>> -recording
>> -playing
>> -running script
>> -finding specified window (FindWindow() )
>> -redirecting voice
>> -buffering
>> -monitoring
>>
>> should I go on?
>> Jack
>>
>>
>> "Veign" <EMail@HideDomain.com> wrote in message
>> news:EMail@HideDomain.com...
>>> Again, I ask, what are you trying to do? By explaining what you ware
>>> doing you may get alternate methods that will work better. When you ask
>>> a specific question you get specific answers - as we don't how or why
>>> things are being used...
>>>
>>> Like, 15 timers on a form, to me, seems very excessive. I have probably
>>> never used more than 3.....
>>>
>>> --
>>> Chris Hanscom - Microsoft MVP (VB)
>>> Veign's Resource Center
>>> http://www.veign.com/vrc_main.asp
>>> Veign's Blog
>>> http://www.veign.com/blog
>>> --
>>>
>>>
>>> "Jack" <replyTo@newsgroup> wrote in message
>>> news:EMail@HideDomain.com...
>>>> Thank you.
>>>> What I am worrying about is that my form has already 15 timers on it
>>>> and I am in need to add some more.
>>>> Not all the timers are active at the same time of course, but one or
>>>> two.
>>>> I do not want to have big overhead, or the code became too 'heavy'.
>>>> Jack
>>>> "Jack" <replyTo@newsgroup> wrote in message
>>>> news:OJ$EMail@HideDomain.com...
>>>>> Hello,
>>>>> 1.
>>>>> Is there any 'optimal' number of timers can be used on one form?
>>>>> 2.
>>>>> Which design will be more efficient:
>>>>> A. using one timer and combine different events using If... Then
>>>>> statements.
>>>>> Because each event requires different time interval change timer
>>>>> intervals for each event will be included in the code
>>>>> or
>>>>> B.
>>>>> For each event use different timer with preset time interval
>>>>>
>>>>> Your thoughts please,
>>>>> Jack
>>>>>
>>>>>
>>>>
>>>>
>>>
>>>
>>
>>
>
>


 
 
Larry





PostPosted: Sat Feb 04 19:29:28 CST 2006 Top

Visual Basic >> Using timers
"Jack" <replyTo@newsgroup> wrote
> Hello,
> 1.
> Is there any 'optimal' number of timers can be used on one form?

Yes, the optimal number might be just one.

> 2.
> Which design will be more efficient:
> A. using one timer and combine different events using If... Then
> statements.

Using less timers would be better. No matter how many timers you
use, you can only execute in one routine at a time anyway....

LFS


 
 
Veign





PostPosted: Sat Feb 04 22:12:33 CST 2006 Top

Visual Basic >> Using timers OK..

You really haven't provided enough information on coming up with an
alternate solution. By the sound of the complexity of your application I'm
not sure you could. What's hard to tell is the why. Like why does running
a script require a timer or why does finding a window need a timer.

I guess I stand by my original statement that a single timer that monitors
all the events is the way to go. Also, its hard to tell if you even need
everything on timers.

Maybe what you could do is start consolidating timers that perform a common
function like; Recording, playback, redirect. See how this works for you
and keep moving in the direction of removing timers and not adding new
ones...

Also, I guess it would be nice to try and understand 'why so many things
need times'

--
Chris Hanscom - Microsoft MVP (VB)
Veign's Resource Center
http://www.veign.com/vrc_main.asp
Veign's Blog
http://www.veign.com/blog
--


"Jack" <replyTo@newsgroup> wrote in message
news:EMail@HideDomain.com...
> No need to get offended. If you are, I apologize.
> I have just tried to answer your question.
> You asked me what I am trying to do and I explained.
> Each timer has specific task as shown. At most only one or two timers are
> active at the same time.
> What I am trying to find is how that timers are weighting on my code?
> Is there a better approach to reduce number of timers and cumulate more
> code inside them?
> It was my original question, btw,
> Jack
>
> "Veign" <EMail@HideDomain.com> wrote in message
> news:enwL%EMail@HideDomain.com...
>> Good luck. You seem very hesistant to give information and when you do
>> you come across with an attitude. I was trying to help.
>>
>> To answer your question - No, you don't need to go on....
>>
>> --
>> Chris Hanscom - Microsoft MVP (VB)
>> Veign's Resource Center
>> http://www.veign.com/vrc_main.asp
>> Veign's Blog
>> http://www.veign.com/blog
>> --
>>
>>
>> "Jack" <replyTo@newsgroup> wrote in message
>> news:%EMail@HideDomain.com...
>>> It is a communication program.
>>> timers are used for:
>>> -main timer --> heart of the system
>>> -retrieving TAPI callbacks
>>> -detecting busy line
>>> -scheduler
>>> -recording
>>> -playing
>>> -running script
>>> -finding specified window (FindWindow() )
>>> -redirecting voice
>>> -buffering
>>> -monitoring
>>>
>>> should I go on?
>>> Jack
>>>
>>>
>>> "Veign" <EMail@HideDomain.com> wrote in message
>>> news:EMail@HideDomain.com...
>>>> Again, I ask, what are you trying to do? By explaining what you ware
>>>> doing you may get alternate methods that will work better. When you
>>>> ask a specific question you get specific answers - as we don't how or
>>>> why things are being used...
>>>>
>>>> Like, 15 timers on a form, to me, seems very excessive. I have
>>>> probably never used more than 3.....
>>>>
>>>> --
>>>> Chris Hanscom - Microsoft MVP (VB)
>>>> Veign's Resource Center
>>>> http://www.veign.com/vrc_main.asp
>>>> Veign's Blog
>>>> http://www.veign.com/blog
>>>> --
>>>>
>>>>
>>>> "Jack" <replyTo@newsgroup> wrote in message
>>>> news:EMail@HideDomain.com...
>>>>> Thank you.
>>>>> What I am worrying about is that my form has already 15 timers on it
>>>>> and I am in need to add some more.
>>>>> Not all the timers are active at the same time of course, but one or
>>>>> two.
>>>>> I do not want to have big overhead, or the code became too 'heavy'.
>>>>> Jack
>>>>> "Jack" <replyTo@newsgroup> wrote in message
>>>>> news:OJ$EMail@HideDomain.com...
>>>>>> Hello,
>>>>>> 1.
>>>>>> Is there any 'optimal' number of timers can be used on one form?
>>>>>> 2.
>>>>>> Which design will be more efficient:
>>>>>> A. using one timer and combine different events using If... Then
>>>>>> statements.
>>>>>> Because each event requires different time interval change timer
>>>>>> intervals for each event will be included in the code
>>>>>> or
>>>>>> B.
>>>>>> For each event use different timer with preset time interval
>>>>>>
>>>>>> Your thoughts please,
>>>>>> Jack
>>>>>>
>>>>>>
>>>>>
>>>>>
>>>>
>>>>
>>>
>>>
>>
>>
>
>


 
 
TedF





PostPosted: Sat Feb 04 23:23:58 CST 2006 Top

Visual Basic >> Using timers
Even though with one timer, still none will work
with the intervals you expect. Because VB can do one thing
at a time, and by the time you expect it to run your function
at the interval you set, it will be busy doing the first function.

You have to run things in sequence rather than by timer intervals.
And don't expect it to run things for you in intervals of 250 or 500,
because it would take that long to run your first function.

Yes timers do run in the background, but will not function
if you have it busy doing something else.

Use one timer.
Set a long variable to count time, then call functions
when the variable reaches time desired.


'Example:
Dim T500 As Long, T750 As Long, T1000 As Long, T1250 As Long
Private Sub Form_Load()
Timer1.Interval = 250
End Sub

Private Sub Timer1_Timer()
T500 = T500 + 1
If T500 = 2 Then
T500 = 0
Call theFunction500
End If

T750 = T750 + 1
If T750 = 3 Then
T750 = 0
Call theFunction750
End If

T1000 = T1000 + 1
If T1000 = 4 Then
T1000 = 0
Call theFunction1000
End If
End Sub
Public Sub theFunction500()
MsgBox "500"
End Sub
Public Sub theFunction750()
MsgBox "750"
End Sub
Public Sub theFunction1000()
MsgBox "1000"
End Sub



"Jack" <replyTo@newsgroup> wrote in message
news:EMail@HideDomain.com...
> No need to get offended. If you are, I apologize.
> I have just tried to answer your question.
> You asked me what I am trying to do and I explained.
> Each timer has specific task as shown. At most only one or two timers are
> active at the same time.
> What I am trying to find is how that timers are weighting on my code?
> Is there a better approach to reduce number of timers and cumulate more
> code inside them?
> It was my original question, btw,
> Jack
>
> "Veign" <EMail@HideDomain.com> wrote in message
> news:enwL%EMail@HideDomain.com...
>> Good luck. You seem very hesistant to give information and when you do
>> you come across with an attitude. I was trying to help.
>>
>> To answer your question - No, you don't need to go on....
>>
>> --
>> Chris Hanscom - Microsoft MVP (VB)
>> Veign's Resource Center
>> http://www.veign.com/vrc_main.asp
>> Veign's Blog
>> http://www.veign.com/blog
>> --
>>
>>
>> "Jack" <replyTo@newsgroup> wrote in message
>> news:%EMail@HideDomain.com...
>>> It is a communication program.
>>> timers are used for:
>>> -main timer --> heart of the system
>>> -retrieving TAPI callbacks
>>> -detecting busy line
>>> -scheduler
>>> -recording
>>> -playing
>>> -running script
>>> -finding specified window (FindWindow() )
>>> -redirecting voice
>>> -buffering
>>> -monitoring
>>>
>>> should I go on?
>>> Jack
>>>
>>>
>>> "Veign" <EMail@HideDomain.com> wrote in message
>>> news:EMail@HideDomain.com...
>>>> Again, I ask, what are you trying to do? By explaining what you ware
>>>> doing you may get alternate methods that will work better. When you
>>>> ask a specific question you get specific answers - as we don't how or
>>>> why things are being used...
>>>>
>>>> Like, 15 timers on a form, to me, seems very excessive. I have
>>>> probably never used more than 3.....
>>>>
>>>> --
>>>> Chris Hanscom - Microsoft MVP (VB)
>>>> Veign's Resource Center
>>>> http://www.veign.com/vrc_main.asp
>>>> Veign's Blog
>>>> http://www.veign.com/blog
>>>> --
>>>>
>>>>
>>>> "Jack" <replyTo@newsgroup> wrote in message
>>>> news:EMail@HideDomain.com...
>>>>> Thank you.
>>>>> What I am worrying about is that my form has already 15 timers on it
>>>>> and I am in need to add some more.
>>>>> Not all the timers are active at the same time of course, but one or
>>>>> two.
>>>>> I do not want to have big overhead, or the code became too 'heavy'.
>>>>> Jack
>>>>> "Jack" <replyTo@newsgroup> wrote in message
>>>>> news:OJ$EMail@HideDomain.com...
>>>>>> Hello,
>>>>>> 1.
>>>>>> Is there any 'optimal' number of timers can be used on one form?
>>>>>> 2.
>>>>>> Which design will be more efficient:
>>>>>> A. using one timer and combine different events using If... Then
>>>>>> statements.
>>>>>> Because each event requires different time interval change timer
>>>>>> intervals for each event will be included in the code
>>>>>> or
>>>>>> B.
>>>>>> For each event use different timer with preset time interval
>>>>>>
>>>>>> Your thoughts please,
>>>>>> Jack
>>>>>>
>>>>>>
>>>>>
>>>>>
>>>>
>>>>
>>>
>>>
>>
>>
>
>