1 Replies - 3169 Views - Last Post: 05 July 2007 - 05:05 PM Rate Topic: -----

#1 FliP1992   User is offline

  • D.I.C Head

Reputation: 14
  • View blog
  • Posts: 200
  • Joined: 14-June 07

Timer :S

Post icon  Posted 05 July 2007 - 01:05 PM

yes i know there is other post explaining the timer but i just cant get my head around linking it with my problem.

im stuck,
i just cant get my head around the code of the timer and how i can get it to show up with a numbers counting-down
also wont when the timer hits 0 a command butten to show up and link to diffent form

i would greatly appreciate a helping code or link a.s.a.p

thanks :D

Is This A Good Question/Topic? 0
  • +

Replies To: Timer :S

#2 5ubw0r1d   User is offline

  • D.I.C Head
  • member icon

Reputation: 2
  • View blog
  • Posts: 78
  • Joined: 18-May 07

Re: Timer :S

Posted 05 July 2007 - 05:05 PM

Ok. First off take my advice with a pinch of salt since my VB experience is in VB.NET and not in VB 6.0 which is what I think you are using.

To start off you want to add a timer from the tool menu to your form. Once on your form you want to go to the properties of that timer. Should show up in a small box on the bottom right hand corner once you click the timer on your form. If not you should be able to get it by the left click menu when you select your timer.

On the properties of the timer you want to set the enabled timer to true or enabled or whatever it is. Then you want to set your time interval. Notice that this is in miliseconds and not seconds. So....

1 second = 1000
2 seconds = 2000
10 seconds = 10000

...and so on.

Once you've done this you want to add the variable you wish to count down. Lets assume you name the variable number and it is assigned to a label.

So obviously you change the label text to display the number variable.

Now you want to decrement the value by one until the number has reached zero.

To do this you must first start the timer. If you place the start timer command in the form load event handler then the timer will start when the form loads. Lets assume you have done this. In order to start the timer in VB.NET you would write


That of course assumes that your timer is named timer1. If this is not how to start the timer in VB 6.0 then a simple google search for "start VB timer" or something similar should let you know how its done.

Now that your timers started it will count 1 second. But will not do anything until you have told it to do so.

To do this you must create and event handler for the timer tick. In VB.NET this is done by selecting the timer and then selecting the events that control can do.

In the event handler you will enter the code to be run everytime your timer counts 1 second. If you wish to count down this would be done as follows

 number = number -1 

If you wished to count upwards this would be done as follows

number = number + 1

This however will not be enough if you want code to be executed when your timer reaches zero.

To do this you want to enclose the above statement within a conditional statement.

Something like....

If number = 0 then
		 'insert your code here
		 Else number = number - 1 

Don't take the above conditional statement as the gospel however, as there are a number of different ways to achieve this result but they all depend on whatever you want to do when the timer reaches zero.

I hope this has been of some help to you and if it does not directly help you with the code in the VB 6.0 enviroment it will at least help you understand a bit how timers work. Please remeber though, in order for you to understand your code better it is best to use your own variable names where appropriate, including for objects such as the timer and the label. It makes code far easier to understand if you have meaningful names for lables such as lbltime, lblelapsedtime, lblend; instead of label1, label2, label3 and so on.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1