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