1

I have a condition in my code similar to:

If not IsNumeric(x) Then ...
End If

when x = "2.50+ or x = "2.50- or any other valid number with '+' or '-' tacked on to the end, IsNumeric(x) returns True!

So both examples of x are valid numeric types for VBScript, but I can't find anything online that documents or suggests this. Why does VBScript allow this, and what would it be used for?

Dane Lowrey
  • 170
  • 1
  • 10
  • Apparently putting the plus/minus sign at the end is a [valid way](https://support.microsoft.com/en-us/kb/42964) to format a number, so `isnumeric` recognizes it (so do `val`/`cdbl`). – GSerg Sep 26 '16 at 21:44
  • 2
    Accountants think that is entirely valid. They also like (2.50) to make it not so obvious that money was lost. And $2.50. And 2.50R. Etcetera, VScript's glass is always half-full. – Hans Passant Sep 26 '16 at 21:59
  • ISNumeric in the VBA spec checks the value type is numeric (except for date). In practise it probably means it does a CInt, CLng, or CDbl and see if any are successful. This is the overall rules for Let Coercion from VBA Language Spec (VBS 99.99% compliant in the features it implements) - –  Sep 26 '16 at 22:38
  • 1
    *The formats accepted or produced when coercing number, currency and date values to or from String respects host-defined regional settings. Excess whitespace is ignored at the beginning or end of the value or when inserted before or after date/time separator characters such as "/" and ":", sign characters such as "+", "-" and the scientific notation character "E".* (5.5.1.2.4 Let-coercion to and from String) There is a page of more detailed rules. https://msdn.microsoft.com/en-us/library/dd361851.aspx –  Sep 26 '16 at 22:41
  • Awesome, thanks for the links to the documentation! @Noodles – Dane Lowrey Sep 30 '16 at 20:54

0 Answers0