Dealing with a group of Timers

  • Thread starter Thread starter N! Xau
  • Start date Start date
N

N! Xau

hi

I need a way to threat a certain number of timers in a homogeneous way.

Let's say I have this code:

select X
case 1
timer1.enabled = true
case 2
timer2.enabled = true
case 3
timer3.enabled = true
case 4
timer4.enabled = true
....
case 19
timer19.enabled = true
case 20
timer20.enabled = true
end select

Timers' names differ by the last 1 or 2 digits.
Can I do all this "passing" X to the name of the timer I want to
select? something like:
timerX.enabled = true
passing X at runtime

thanks
N! Xau
 
Hi there,

Put them into an array list,

dim pop as new arraylist
pop.add(timer1)
pop.add(timer2)
pop.add(timer3)

ctype(pop.item(x),timers.timer).enabled = true

^Untested code BTW, but i think you see the idea.

Nick.
 
NXau,

Are you sure that you use the system.timers.timer (where you are casting too
now) and not the forms.timer?

It can than be
dim pop as new arraylist
pop.add(timer1)
pop.add(timer2)
pop.add(timer3)

directcast(pop(x),forms.timer).enabled = true


There are 3 timers in Net.

I hope this helps,

Cor
 
Cor Ligthert [MVP] ha scritto:
NXau,

Are you sure that you use the system.timers.timer (where you are casting too
now) and not the forms.timer?

Cor, I am using the timers added at design time on the form, so I guess
it's forms.timer
It can than be
dim pop as new arraylist
pop.add(timer1)
pop.add(timer2)
pop.add(timer3)

directcast(pop(x),forms.timer).enabled = true
There are 3 timers in Net.


What differences between them and what is better to use?

Thanks
N! Xau
 
N!Xau
What differences between them and what is better to use?

If it is in a form class than you can use form.timers

If it is not in a form than you can use the system.timers

When it is about threading, than you can use threading.timers

(The last one I try to avoid as hell because it runs on its own thread and
will always fire even if the thread has already ended)

That is the sequence I do it. However, just my way.

Cor
 
Cor Ligthert [MVP] ha scritto:
If it is in a form class than you can use form.timers

If it is not in a form than you can use the system.timers


My timers are form.timers

Is there a way to adapt that code to work even with such timers?


THX
 
N! Xau ha scritto:
Cor Ligthert [MVP] ha scritto:


anyway, I get an error "undefined type forms.timer"


OK I finally got it. I had to write
....(pop(x),windows.forms.timer)...

I don't understand why, seen I have a
imports system.windows.forms
as well.


Thanks
 
Back
Top