Odd or Even
I didn't even evaluate the previous poster's method - I guess I assumed
that since it was in all caps, it was a worksheet solution, and you were
correcting it. No offense meant!
The solution I provided in a different subthread assumed that "variable"
was of the appropriate type, which I should have pointed out.
I think that the fix to your function would depend on the situation -
rather than "Invalid value", which necessitates the function return a
variant, it might be more appropriate to keep the boolean function and
return False. One could even explicitly type Val as a Long, and perform
the implicit coercion in which a single or double would be rounded.
In article ,
"Bob Phillips" wrote:
Strange, 1.3 MOD 2 also returns 1 which the previous poster called as Odd,
but you didn't seek to point that out?
And if non-integer values need to be catered for it is easily extended
Public Function IsOdd(Val)
If Val \ 1 < Val Then
IsOdd = "Invalid value"
Else
IsOdd = (Val \ 2) * 2 < Val
End If
End Function
|