View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Bob[_77_] Bob[_77_] is offline
external usenet poster
 
Posts: 61
Default Error with a boolean operation

Hi everyone:

In excel VBA, I have the following code:

Public Function MY_tester(z, w)
On Error GoTo ErrHandler

If Not IsNumeric(z) Then
MY_tester = "Error: Z must be a number"
ElseIf Not IsNumeric(w) Then
MY_tester = "Error: w must be a number"
ElseIf ((z + w) < 0) And ((z + w) = Fix(z + w)) Then
MY_tester = "Error: z+w cannot be zero nor negative integers"
Else
MY_tester = "Answer OK"
End If

ErrHandler:
If Err Then
MY_tester = "Error: " & Err.Description
End If
End Function

Public Sub MY_SUB()
MsgBox MY_tester(-4.4, 3.4)
End Sub

When I run the sub MY_SUB, the program returns false for ((z + w) = Fix(z +
w)) , even though it is true (after all, -1 is equal to -1). Does anyone
know why? I think this may be a bug in VBA. I appreciate all your help.

Bob