To infinity and beyond in VBA To infinity and beyond in VBA vba vba

To infinity and beyond in VBA


Since a Double.NAN field represents a value that is not a number, you're very likely on the right track using a string comparison.

If you were going the other way (i.e., passing values out of VB), ByRef and ByVal are the usual suspects.

VB's IsNumeric() function isn't always intuitive. For example, it will return True if an alphanumeric code happens, by chance, to be a number in scientific notation.


I agree with David that your current workaround is acceptible. Be sure to test on foreign language installs though!

There example that you give could be part of the solution: a value that is equal to 1 and to 0 at the same time, is not a normal number. That test can distinguish NaNs from normal numbers. Possibly you can find similar rules like this to find +/-infinity.


Make sure you take into account current locale.NaN can be "-1.#IND" or "-1,#IND" depending on decimal separator settings.

One way to avoid this may be InStr comparison:

InStr(CStr(dVal), "#IND") <> 0