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.
creating a visible timer in visual basic
Collapse
X
-
Tags: None
-
Originally posted by terry guthrieI 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.
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...
[CODE=vb]Option Explicit
DefLng A-Z
Private StartTime As Long
Private Sub Form_Load()
StartTime = Timer
End Sub
Private Sub Timer1_Timer()
Label1.Caption = CLng(Timer - StartTime)
End Sub[/CODE] -
Hi, see if this helps at all...
Display Time
[CODE=vbnet]Private Sub Timer1_Tick(ByV al sender As System.Object, ByVal e As System.EventArg s) Handles Timer1.Tick
TimeToolStripMe nuItem.Text = Now.ToLongTimeS tring() 'Display time in menu strip
End Sub[/CODE]Comment
Comment