Computing.Net > Forums > Programming > Simple Timing

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Simple Timing

Reply to Message Icon

Name: BaBa
Date: August 23, 2002 at 21:13:24 Pacific
Comment:

Hi guys,

I'm trying to create a timing. can somone give me an idea?

This is what I want to do. I want to show a number in a textbox, then wait 3 second before another number shows up, then another 3 seconds and another number, so on and so forth. How can I do that using the timer control in VB?



Sponsored Link
Ads by Google

Response Number 1
Name: Sebastian
Date: August 23, 2002 at 23:13:28 Pacific
Reply:

Well, I program in C/C++, but I'm sure this will be similar in VB.

Create a timer, ie:

SetTimer(hwnd, id, duration, NULL);

...where duration @3000 = 3 seconds.

case WM_TIMER:

sprintf(buff, "%i", number);

SetWindowText(hwndTextBox, buff);

break;


//...be sure to call KillTimer() when yer done:)


0

Response Number 2
Name: Jim
Date: August 24, 2002 at 18:13:40 Pacific
Reply:

Actually, it's even easier than that in VB. You just set the timer delay to 3000, so it will fire every 3 seconds. Then you bring up the timer event routine and program it to change the number in the text box.


0

Response Number 3
Name: BaBa
Date: August 24, 2002 at 19:37:06 Pacific
Reply:

Hi guys,

I truly want to thank you for you efforts trying to help me. You guys make me feel that I'm not alone.

Sebatian,
VB is very different from C/C++.

Jim,
When a code is placed in the timer routine, the same code keeps running every number of seconds that the timer interval was set for.
I wonder if you can give me an example in code. It doesn't have to be exact. Just to give me a better idea.

If I had only one Label, I could use the Rnd function to just change the number every 3 seconds. However, I have many labels on the screen and I want the number to disappear and reappear on a different label each time. I need a different kind of timing other than the timer.

Once again thanks!


0

Response Number 4
Name: Jim
Date: August 25, 2002 at 19:59:18 Pacific
Reply:

> If I had only one Label, I could use the Rnd function to just change the number every 3 seconds. However, I have many labels on the screen and I want the number to disappear and reappear on a different label each time. I need a different kind of timing other than the timer.

If I understand correctly, this would still be easier with only one timer. Unless you wanted to place several timers and mess with their Timer.Enabled properties. I can think of two ways to change the number of multiple labels from one timer.

1) Use rnd and a case statement or multiple if thens to choose which label to put the number on next.

2) Create an array of label controls, and use rnd to determine which label to put the number on next, and a subscript to put it there.

To do it the first way, you may want to declare a global (or static) variable, and have it contain the "index" of the label that currently has the numner. define CurrentIndex as integer

Then your timer routine could look something like this:

// First, Make the number disappear

if CurrentIndex = 1 then
    Label1.Caption = ""
else if CurrentIndex = 2 then
    Label2.Caption = ""
else if CurrentIndex = 3 then
    Label3.Caption = ""

...

// Determine where to move it

CurrentIndex = rnd(NUMBER_OF_LABELS) + 1

// Now make it reappear on the new label

if CurrentIndex = 1 then
    Label1.Caption = Number
else if CurrentIndex = 2 then
    Label2.Caption = Number
else if CurrentIndex = 3 then
    Label3.Caption = Number
...

I apologize if I got the property name wrong, or the randomize syntax. VB is not installed on this machine at the moment. You should get the idea, though.


0

Response Number 5
Name: BaBa
Date: August 31, 2002 at 13:42:31 Pacific
Reply:

Hi guys,

Thank you guys!!

Jim,
Everything went fine. I only used one label. I moved it around the screen using the Rnd function, the top and left property of the label. The program runs fine.

Once again thanks!!



0

Related Posts

See More



Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Simple Timing

Simple (I hope) batch file problem www.computing.net/answers/programming/simple-i-hope-batch-file-problem/12736.html

batch file, display time www.computing.net/answers/programming/batch-file-display-time/2950.html

A simple program in C/C++ www.computing.net/answers/programming/a-simple-program-in-cc/13831.html