Timers

  • Thread starter Thread starter Earl Partridge
  • Start date Start date
E

Earl Partridge

I have 6 labels that I want to display, one at a time, in 15 second intervals. After all 6 have
been displayed, I want to restart, displaying all 6 again, continuously.
Experimenting with just 2 labels and 1 timer, I set the timer Interval accordingly, then I make
Label1.visible False, and Label2.visible True, and this works fine, but I'm a bit confused as to
how to continue with Labels 3 - 6, and how to restart at #1 again.
Earl
 
I have 6 labels that I want to display, one at a time, in 15 second
intervals. After all 6 have
been displayed, I want to restart, displaying all 6 again, continuously.
Experimenting with just 2 labels and 1 timer, I set the timer Interval
accordingly, then I make
Label1.visible False, and Label2.visible True, and this works fine, but I'm
a bit confused as to
how to continue with Labels 3 - 6, and how to restart at #1 again.
Earl

A question first. Do you have all the labels defined on the page.

If you do then it is simple.

Create a list(of Label) and add in reverse order the labels you want shown
all 6.

Now enable the timer that has a 15 second interval.

On the timer event disable the timer, use the list's 0 element and show it.
Then remove the 0 element.
If the list count = 0 then reset the list with the 6 labels.
Then enable the timer.

This should just keep on going like that battery bunny.

Hope this helps
Lloyd Sheen
 
I will have 6 labels on the same "Form", added from the Toolbox.
By list(of label) do you mean use a ListBox?
Also, I've asked in another thread "Full Screen" but still not able to size
the
label to fill the entire form. Any thoughts?
Thanks.
Earl
 
Earl Partridge said:
I will have 6 labels on the same "Form", added from the Toolbox.
By list(of label) do you mean use a ListBox?
Also, I've asked in another thread "Full Screen" but still not able to
size the
label to fill the entire form. Any thoughts?
Thanks.
Earl

By list(of label) I mean a collection of labels.

If you have the lables on the form already you can do the following:

dim myLabels as new list(of Label)

myLabels.add(Label1) or whatever the name is. Do the same for the other 5
again in reverse order.

what you are doing is creating a list of things to do. Each time the timer
event happens you will take the first element and do what you need to do
with it , at the same time deleting it from the list. When the list goes
empty you will reset the list.

as for the label showing full screen, you would have to make the form bigger
than the screen (just a few pixels would do) and then set the forms location
such that its top left have negative coordinates. Then you would resize the
label so that it fills the form. this will then show as "full screen". It
is a kludge but I know no other way to do it.

LS
 
I have 6 labels that I want to display, one at a time, in
15 second intervals. After all 6 have been displayed,
I want to restart, displaying all 6 again, continuously.

If you are using Visual Basic then you can create an array of Labels with
indexes 0 to 5 (or 1 to 6 or whatever you are most comfortable with) and
then in the Timer routine you can set up a Static variable as a counter and
refer to each of the Labels in turn using its Index property, incrementing
the counter each time the Timer routine fires. When you get to the last
Label in the array then simply set your Static variable back to 0 (or 1 or
whatever is the Index of the first Label in the array).

Mike
 
By list(of label) I mean a collection of labels.

If you have the lables on the form already you can do the following:

dim myLabels as new list(of Label)

myLabels.add(Label1) or whatever the name is. Do the same for the other 5
again in reverse order.

what you are doing is creating a list of things to do. Each time the timer
event happens you will take the first element and do what you need to do
with it , at the same time deleting it from the list. When the list goes
empty you will reset the list.

as for the label showing full screen, you would have to make the form bigger
than the screen (just a few pixels would do) and then set the forms location
such that its top left have negative coordinates. Then you would resize the
label so that it fills the form. this will then show as "full screen". It
is a kludge but I know no other way to do it.

LS

Loyd,

I think you have the right idea, but it a Queue(Of Label) might actually
work better in this case....

psuedo code:


private workQueue as new queue(of label)

sub new()
initializecontrols()
workQueue.Enqueue (label1)
workQueue.Enqueue (label2)
workQueue.Enqueue (label3)
workQueue.Enqueue (label4)
workQueue.Enqueue (label5)
workQueue.Enqueue (label6)
end sub

sub timer_proc () handles timer
dim current as label = workQueue.Dequeue()

' do stuff with label

workQueue.Enqueue (current)
end sub

Self rotating list :) Every 15 seconds, you remove the top entry, do
you stuff and then put it back on the end.
 
I'm afraid I'm out of my league, having done no VB programming for about the
past
12 years... never got into "collections". I may have to try that array
suggestion Mike
Williams suggested.

As for Lloyd's suggestion for list(of label), would that coding go for the
form.load or
in the timer section? Would there be an example somewhere I could view?

Thanks for the effort guys.

Earl
 
I'm afraid I'm out of my league, having done no VB programming for about the
past
12 years... never got into "collections". I may have to try that array
suggestion Mike
Williams suggested.

As for Lloyd's suggestion for list(of label), would that coding go for the
form.load or
in the timer section? Would there be an example somewhere I could view?

Mikes solution is not going to work for you... Simply because there is
no such thing as a control array in VB.NET. He is purposely suggesting
a VB6 solution to a VB.NET problem.

All I can tell you is that Collections are fundamental part of
progamming in any language, so it's a good a time as any to learn them
:)

Queue(Of T) and List(Of T) are located in the System.Collections.Generic
namespace. Which is a good place to start in the documentation...
 
Mikes solution is not going to work for you... Simply because there is
no such thing as a control array in VB.NET. He is purposely suggesting
a VB6 solution to a VB.NET problem.

All I can tell you is that Collections are fundamental part of
progamming in any language, so it's a good a time as any to learn them
:)

Queue(Of T) and List(Of T) are located in the System.Collections.Generic
namespace. Which is a good place to start in the documentation...

Though thinking about it more... If you need to do different things to
each lable that depends on the order, then you can do sort of the same
thing. Just put your labels in a list(of label) and keep track in the
timer event...

public class form1
inherits system.windows.forms.form

private labels as new list(of label)

public sub new()
initializecomponents()

labels.add(label1)
lables.add(label2)
labels.add(label3)
lables.add(label4)
lables.add(label5)
lables.add(label6)
end sub

private subtimer1_timer(byval sender as object, byval e as eventargs) handles timer1.timer
static index as integer = 0

dim current as label = labels(index)
select index
case 0
' do 0 stuff
case 1
' do 1 stuff
case 2
' do 2 stuff
...
case 5
'do 5 sutff
end select

index += 1
if (index > list.count)
index = 0
end sub

end class

Of course, if you don't do different stuff, then the queue would
probably work pretty well for you.
 
Tom and Loyd

I don't think that a whatever list or collection here has any advantage over
a simple array of labels.

dim timerLabels(5) = {Label1, label2, label3, label4, label5, label6}
older VB versions from this milenium than version 2008
dim timerLabels(5) as label = {Label1, label2, label3, label4, label5,
label6}

This is in my idea here the most effective, because it is just a fixed
array.

(This also written because of the confusion by the OP about a control array,
of course there can be arrays of controls, they don't however have that
limited use as in VB versions from the previous milenium).

Cor
 
Hey Earl,

I think Cor's solution will probably work best for you.

First declare the array of labels anywhere inside you Form:

Private Labels() As Label = {Label1, Label2, Label3, Label4, Label5,
Label6}

Then you need an index, so add somehtign like:

Private labelIndex as Int32 ' you can use Integer if you prefer


Then in your Timer's tick event write something like this :


Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Timer1.Tick

Labels(labelIndex).Visible = Not Labels(labelIndex).Visible
labelIndex += 1
If labelIndex >= Labels.Length Then labelIndex = 0

End Sub


Note: I toggled the visibility of the label, you might want to do other
stuff, but that should give you the basics.
 
Tom and Loyd

I don't think that a whatever list or collection here has any advantage over
a simple array of labels.

dim timerLabels(5) = {Label1, label2, label3, label4, label5, label6}
older VB versions from this milenium than version 2008
dim timerLabels(5) as label = {Label1, label2, label3, label4, label5,
label6}

This is in my idea here the most effective, because it is just a fixed
array.

(This also written because of the confusion by the OP about a control array,
of course there can be arrays of controls, they don't however have that
limited use as in VB versions from the previous milenium).

Cor

An array works as well. I was leaning towards a queue initially,
simply because of the fact that it can self rotate - no need of the
extra variable to track the index :)
 
If you are using Visual Basic then you can create an array of Labels with
indexes 0 to 5 (or 1 to 6 or whatever you are most comfortable with) and
then in the Timer routine you can set up a Static variable as a counter and
refer to each of the Labels in turn using its Index property, incrementing
the counter each time the Timer routine fires. When you get to the last
Label in the array then simply set your Static variable back to 0 (or 1 or
whatever is the Index of the first Label in the array).

Mike

Sigh,

Please tell me I'm not going to have to treat you like I used to treat
aaron kempf and follow you through the threads and mark them as
trolling attempts? I hope you are adult enough to realize the
silliness and pointlessness of trolling the .NET newsgroup. We (.NET
and classic vb newsgroups) are not "at war" with each other, and there
is not reason for either side to start trolling on the other's
newsgroup.

From what you say you're doing this because of Bill McCarthy, who you
accuse of trolling the classic vb newsgroup. If he was (which from the
thread I saw it appears he was), and you really are against that sort
of behavior, then why do you think it's a good idea for you to do it
as well? Fighting fire with fire usually only results in both sides
getting burned. The only thing you will achieve from this is
tarnishing your image, something I'm sure you don't want as you have
been, and are, a useful classic vb resource.

Thanks,

Seth Rowe [MVP]
 
Mikes solution is not going to work for you... Simply
because there is no such thing as a control array in
VB.NET. He is purposely suggesting a VB6 solution
to a VB.NET problem.

.. . . in exactly the same way that Bill McCarthy, who has been trolling the
VB6 group for months, purposely suggests vb.net solutions to VB6 questions
on the VB6 group. I've only just started doing it here. McCarthy has been
doing it for months on the VB6 group. Perhaps he might like to sop doing it?

Mike
 
Sigh, Please tell me I'm not going to have to treat you
like I used to treat aaron kempf and follow you through
the threads and mark them as trolling attempts?

Yep. That's what it looks like you're going to have to do. Unless of course
McCarthy stops trolling the VB6 group, which he's been doing for months, or
unless I stop following him here :-)
I hope you are adult enough to realize the silliness and
pointlessness of trolling the .NET newsgroup. We (.NET
and classic vb newsgroups) are not "at war" with each other,
and there is not reason for either side to start trolling on the
other's newsgroup.

You are quite correct, Seth. It is thoroughly annoying and it should be
totally unnecessary. None of us should engage in such activities.
From what you say you're doing this because of Bill
McCarthy, who you accuse of trolling the classic vb
newsgroup. If he was (which from the thread I saw
it appears he was), and you really are against that sort
of behavior, then why do you think it's a good idea
for you to do it as well?

I don't think it is a good idea. In fact it is a bad idea. But I am doing it
as a last resort because McCarthy has almost totally destroyed the classic
VB group as far as many of its participants are concerned and, to be frank,
this is a sort of "last resort" attempt of mine to try to persuade him to
stop trolling it.
Fighting fire with fire usually only results in both
sides getting burned. The only thing you will achieve
from this is tarnishing your image

Yes. I'm aware of that. But it's getting a bit desperate over there and so
I'll have to take the risk. McCarthy just refuses to let go. I used to
really love participating in the VB classic group, but McCarthy is forcing
lots of people to consider leaving it, which is of course his aim, and so
I'm trying to get him to stop doing it.

Mike
 
Mike Williams said:
. . . in exactly the same way that Bill McCarthy, who has been trolling
the VB6 group for months, purposely suggests vb.net solutions to VB6
questions on the VB6 group. I've only just started doing it here. McCarthy
has been doing it for months on the VB6 group. Perhaps he might like to
sop doing it?

Let it go Mike. Folks here have asked you to stop trolling, and folks in
the Vb6 forum have also told you to stop trying to start flames by your
constant attacks on folks.
As fun as it is to humor you, over the last two weeks you've waged many
personal attacks on me, first claiming I was someone else, then some other
silly conspiracy rant, and most recently your dishonest attack on me because
you say I didn't correct Cor. Your above claim that I provide .net answers
to VB6 questions is in fact a lie, another figment of your imagination
again. I have only provided dotnet answers to dotnet questions.
Oh, and if you think you can bully or intimidate me, you're going to learn a
lesson the hard way. I suggest you talk to folks who know me, as I can
assure you I have been around the VB forums while you were still driving
taxis for a living. The best advice I can give you now Mike, is listen to
the advice everyone is giving you, and desist from any further attacks.

HTH's.
 
Thanks to all for the recommendations, buy you're all way beyond my old time
knowledge. I finally figured out a simple way to do what I want in the
Timer Tick
section... with:

If Second(Now) > 0 And Second(Now) < 11 Then
Label1.Visible = False
Label2.Visible = True
ElseIf Second(Now) > 10 And Second(Now) < 21 Then
Label2.Visible = False
Label3.Visible = True
ElseIf Second(Now) > 20 And Second(Now) < 31 Then

etc, etc.....

Now, I think I'll just see if I can further simplify this by perhaps using
just one
label and change the "text" at the designated time.

Earl
 
And following up with that effort to use a single label and changing the
text... In the Form I read a database and gather a list of names and
birthdays for the current day, put them in a variable. But when I try to
use that variable in the Timer_Tick event, it is not recognized. Perhaps
that's what you folks have been trying to get me to realize.

I suppose I could do that call to the database within the tick event but
that
just seems to be too much wear and tear, or unnecessary work reading
the database. In this case, I'd be building that list every 10 seconds.

The other 5 messages to be displayed in the label are static stuff, only
being changed as warranted.

Earl


Earl Partridge said:
Thanks to all for the recommendations, buy you're all way beyond my old
time
knowledge. I finally figured out a simple way to do what I want in the
Timer Tick
section... with:

If Second(Now) > 0 And Second(Now) < 11 Then
Label1.Visible = False
Label2.Visible = True
ElseIf Second(Now) > 10 And Second(Now) < 21 Then
Label2.Visible = False
Label3.Visible = True
ElseIf Second(Now) > 20 And Second(Now) < 31 Then

etc, etc.....

Now, I think I'll just see if I can further simplify this by perhaps using
just one
label and change the "text" at the designated time.

Earl
 
Back
Top