|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
the stop watch program
i've been give a program to do, my teacher has supplied me with what goes where etc..... but it seems to be a typo because i have checked and this error keeps popping up..
Private Sub cmdStart_Click() ' Store the current date/time (Now) in a variable: StartTime = Now ' Format the stored date/time to show hours, ' minutes, and seconds, and show it in the Label: lblStartTime.Caption = Format(StartTime, "hh:mm:ss") ' Disable the start button (we've already started)... cmdStart.Enabled = False '...and enable the stop button: cmdStop.Enabled = True End Sub the text in colour is the error. I wonder if anyone has any suggestions please many thanks |
|
#2
|
|||
|
|||
|
What's the error?
|
|
#3
|
|||
|
|||
|
the error is claimed to me
StartTime = Now compile error: variable not defined |
|
#4
|
||||
|
||||
|
if you have Option Explicit turned on, then I don't see where you've declared StartTime to be a variable. Declare that variable, and I would assume that it would fix it.
|
|
#5
|
|||
|
|||
|
I do have Option Explicit in the program.
Private Sub Form_Load() ' Declare three variables to hold date/time ' values. Dim StartTime As Variant Dim StopRime As Variant Dim TotalTime As Variant ' Dispable the Stop button (we've not started yet): cmdStop.Enabled = False End Sub this is what i have been told to enter for the decaring variants, so everything is where it should be... but this error continue to state that StartTime = Now is the problem, i cant see the error, can anyone see what i cant |
|
#6
|
||||
|
||||
|
ok.. from what I'm seeing, you're having a problem with scope. You're declaring your variable in form_load, but the variables in form load are not visible to your cmdStart_Click procedure. Unless you require the variable in form_load, cut it, and paste it into the click event for cmdStart. Remember, unless your variable is declared as either module or global - level, it will not be visible to any procedure except the one it is in.
|
|
#7
|
|||
|
|||
|
Ohh cheers m8, understood that, move the Dim stuff to cmdstart and cmdstop, works a treat now, cheers m8
i can keep up with the lads now many thanks |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > Visual Basic Programming > the stop watch program |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|