Error with a boolean operation
Thanks guys for the insight into the problem. Then I guess, there is no way
of knowing if z+w is exactly an integer or not? The reason I need to know
this is that I am evaluating a function that works for all numbers except
exact integers. Even very close to integers will work, but not the integer
itself.
Bob
"Bob" wrote in message
...
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
|