|
-
Apr 9th, 2007, 10:23 AM
#1
Thread Starter
Lively Member
what wrong for my code?
Code:
Private Sub Command1_Click()
Dim degrees As Double
Dim minutes As Double
Dim seconds As Double
Dim decimals As Double
If Text1.Text <> "" Or Text2.Text <> "" Or Text3.Text <> "" Then
degrees = Text1.Text
minutes = Text2.Text / 60
seconds = Text3.Text / 3600
decimals = degrees + minutes + seconds
Label6.Caption = decimals
ElseIf test1.Text = "" And Text2.Text = "" And Text3.Text = "" Then
MsgBox "Please key in your input value", vbCritical, "Degree Converter"
End If
End Sub
if the textbox 1 ,2,3 is empty, i want it give a message.but with the code above, it came out an error "object required". Why?
-
Apr 9th, 2007, 10:30 AM
#2
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)
Sometimes the Programmer
Sometimes the DBA
Mazz1
-
Apr 9th, 2007, 10:32 AM
#3
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.
-
Apr 9th, 2007, 12:19 PM
#4
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
The most difficult part of developing a program is understanding the problem.
The second most difficult part is deciding how you're going to solve the problem.
Actually writing the program (translating your solution into some computer language) is the easiest part.
Please indent your code and use [HIGHLIGHT="VB"] [/HIGHLIGHT] tags around it to make it easier to read.
Please Help Us To Save Ana
-
Apr 9th, 2007, 01:09 PM
#5
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|