Re: what wrong for my code?
In one statement you have Text1 in the Elseif you have test1.Text Which is correct? (my bet is Text1.Text and not test1.Text)
Re: what wrong for my code?
Two things. In your ElseIf you misspelled Text.
Also, please do not use vbCritical.....it tends to scare the heck out of people and the fact that they have not entered anything is not critical. The application will not melt down. All you are trying to do is issue a friendly reminder that they need to input something.
Use either vbInformation or vbExclamation.
Re: what wrong for my code?
Your code will fail if 2 of the 3 textboxes (or even 1 of them) is blank. Try this.
Code:
Private Sub Command1_Click()
Dim degrees As Double
Dim minutes As Double
Dim seconds As Double
Dim decimals As Double
If Trim$(Text1.Text) = "" Or Trim$(Text2.Text) = "" Or Trim$(Text3.Text) = "" Then
MsgBox "Please key in your input values", vbInformation, "Degree Converter"
Else
degrees = CDbl(Text1.Text)
minutes = CDbl(Text2.Text) / 60
seconds = CDbl(Text3.Text) / 3600
decimals = degrees + minutes + seconds
Label6.Caption = decimals
End If
End Sub
Re: what wrong for my code?
The best way is to not let them be blank in the first place. Do this for each textbox. (If you had a control array you'd only have to do it once)
vb Code:
Private Sub Text1_Validate(Cancel As Boolean)
If Trim$(Text1.Text) = "" Then
MsgBox "I'm empty"
Text1.SetFocus
Cancel = True
End If
End Sub