BradB
It helps if you indent code when it is inside "If...Then", and align each "End If" with its "If Then" as it makes the code easier to read:
Code:
If txtAmountOfTime.Text = "" Then
txtAmountOfTime = 1
Else
num2.Text = txtAmountOfTime
If num1 And num2 <> "" Then
txtAmountOfTime.Text = Val(num1.Text) + Val(num2.Text)
End If
End If
is easier to read if you indent it this way:
Code:
If txtAmountOfTime.Text = "" Then
txtAmountOfTime = 1
Else
num2.Text = txtAmountOfTime
If num1 And num2 <> "" Then
txtAmountOfTime.Text = Val(num1.Text) + Val(num2.Text)
End If
End If
Is that what you meant, or did you mean this:
Code:
If txtAmountOfTime.Text = "" Then
txtAmountOfTime = 1
Else
num2.Text = txtAmountOfTime
End If 'End If moved to here
If num1 And num2 <> "" Then
txtAmountOfTime.Text = Val(num1.Text) + Val(num2.Text)
End If
It is even better to comment the End Ifs so that you can tie them together, particularly if they are a long way from the corresponding "If".
Code:
If txtAmountOfTime.Text = "" Then
txtAmountOfTime = 1
Else
num2.Text = txtAmountOfTime
If num1 And num2 <> "" Then
txtAmountOfTime.Text = Val(num1.Text) + Val(num2.Text)
End If 'Num1 not blank and Num2 not blank
End If 'txtAmountOfTime.Text is blank
As has been pointed out, there appears to be an error here:
Code:
If num1 And num2 <> "" Then
I think you mean
"If Num1 isn't blank AND Num2 isn't blank then...."
What you have actually coded is
"If (Num1 ANDed with Num2) is not blank Then...."
The syntax you need here is
Code:
If (num1 <> "") And (num2 <> "") Then
I think you are trying to get to:
Private Sub cmd1Hour_Click()
num1 = 0.5 'Set default value for Num1
'Check value of txtAmountOfTime and assign
'default if blank
If txtAmountOfTime.Text = "" Then
txtAmountOfTime = 0.5
End If 'txtAmountOfTime.Text = ""
'By this point, txtAmountOfTime is either a
'value entered by user, or it is the default value
'of 0.5 so set Num2 to be the same
num2.Text = txtAmountOfTime
If (num1 <>""

And (num2 <> ""

Then
txtAmountOfTime.Text = Val(num1.Text) + Val(num2.Text)
End If
End Sub
[/code]
Hope this helps.
Daren
Must think of a witty signature