-
Ok... i have this simple script but it does not seem to
work. I have a form with two textboxes. I want to retrieve
a time from the user. My script was doing just fine, until
I wanted to limit the input for seconds to 59. Caus' i.e.
2 minutes and 74 seconds is weird. So it made a simple
change. But now my script is acting weird and i get the
wrong messageboxes at the wrong moment. I just want a time
and when the user presses a button, it starts calculating
with it... can anybody HELP ME?
Here's my code:
Code:
Private Sub Command1_Click()
If Text1.Text = "" Then
GoTo error1
ElseIf Text2.Text = "" Then
GoTo error1
End If
If IsNumeric(Text1.Text) Then GoTo proceed Else GoTo error2
If IsNumeric(Text2.Text) Then GoTo proceed Else GoTo error2
proceed:
If Text2.Text > 59 Then
GoTo error3
Else
calculate
End If
error1:
MsgBox "Please enter a value"
GoTo endsub
error2:
MsgBox "Please enter a number"
GoTo endsub
error3:
MsgBox "Seconds must be below 60"
GoTo endsub
endsub:
End Sub
Since this:
Code:
If Text2.Text > 59 Then
it is acting weird...
-
I am so dumb...
never mind...
i forgot to put goto endsub at the end of that part...
so it calculated the stuff... and then did a msgbox
with "please enter a value".... I am so dumb...
-
Get rid of the old fashion goto **** statements and write structural code, also indent code to help your self and others read it easer. Although this program is small and straightforward I could imagine what your bigger programs would be like, hell for any one trying to debug it.
Didn't mean to offend you, just trying to help you improve your coding style. I tell all my mates the same thing, it makes it easer to sort any problem they have because the code is much clearer.
:D :D :D