Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
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?

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:)

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.

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!

> 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.

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!!

![]() |
![]() |
![]() |

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