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

creating a visible timer in visual basic

P: 4
I need some help with visual basic code, I need to create a timer that will be visible while playing a game, i know there is a timer in the tools that you pull over to the project and is hidden, and then i create a label on the page itself, the purpose is to show in seconds how long it takes to complete a game. what is the code that will link the timer with label so when i start my game you can see how many seconds it is taking.
Sep 13 '07 #1
Share this Question
Share on Google+
2 Replies


Expert 5K+
P: 8,434
I need some help with visual basic code, I need to create a timer that will be visible while playing a game, i know there is a timer in the tools that you pull over to the project and is hidden, and then i create a label on the page itself, the purpose is to show in seconds how long it takes to complete a game. what is the code that will link the timer with label so when i start my game you can see how many seconds it is taking.
(Note, I'm assuming VB6 here...)

One simple way would to store the value returned by the Timer() function (ignore the name, it's just a coincidence) when you start, then in the Timer1_Timer event, set the label caption to the difference between that original value and the current time.

For example, create a new form, add a timer (with Interval = 1000) and a label, and paste this into the code window...
Expand|Select|Wrap|Line Numbers
  1. Option Explicit
  2. DefLng A-Z
  3.  
  4. Private StartTime As Long
  5.  
  6. Private Sub Form_Load()
  7.   StartTime = Timer
  8. End Sub
  9.  
  10. Private Sub Timer1_Timer()
  11.   Label1.Caption = CLng(Timer - StartTime)
  12. End Sub
Sep 13 '07 #2

jamesd0142
100+
P: 469
Hi, see if this helps at all...

Display Time

Expand|Select|Wrap|Line Numbers
  1. Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
  2.   TimeToolStripMenuItem.Text = Now.ToLongTimeString() 'Display time in menu strip
  3. End Sub
Sep 14 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.