By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,820 Members | 1,103 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,820 IT Pros & Developers. It's quick & easy.

Dealing with a group of Timers

P: n/a
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

Nov 21 '05 #1
Share this Question
Share on Google+
9 Replies

P: n/a
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.

"N! Xau" <nx**@hotmail.com> wrote in message
news:11**********************@g49g2000cwa.googlegr oups.com...
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

Nov 21 '05 #2

P: n/a
Nick:
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

I added (before your code):
dim x as integer = MyVar ' for instance, MyVar = 2

Executing it, I get a "specified cast is not valid" error.
N! Xau
http://ilovemiliofede.altervista.org

Nov 21 '05 #3

P: n/a
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
Nov 21 '05 #4

P: n/a

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

Nov 21 '05 #5

P: n/a
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
Nov 21 '05 #6

P: n/a

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

Nov 21 '05 #7

P: n/a
Cor:
directcast(pop(x),forms.timer)*.enabled = true

Ok, ok
I hadn't seen you changed the instruction using forms instead of
timers.
Thanks
N! Xau

keep in mind the power of ANTANI
http://ilovemiliofede.altervista.org

Nov 21 '05 #8

P: n/a

Cor Ligthert [MVP] ha scritto:
directcast(pop(x),forms.timer).enabled = true


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

Nov 21 '05 #9

P: n/a

N! Xau ha scritto:
Cor Ligthert [MVP] ha scritto:
directcast(pop(x),forms.timer).enabled = true


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

Nov 21 '05 #10

This discussion thread is closed

Replies have been disabled for this discussion.