Din lngAge

lngAge = InputBox("Plese enter your age in years")

MsgBox "TypeName After InputBox: " & TypeName(lngAge)

If IsNumeric(lngAge) Then

lngAge = lngAge + 50

MsgBox "TypeName after Adding 50: " &TypeName(lngAge)

MsgBox "In 50 years you will be " & lngAge & "years old."

Else

MsgBox "Sorry, but you did not enter a valid number."

End If

In the example above, VBScript automatically knew that we wnated the value the variable to be a number because our code added 50 to the variable. VBScript says, "Oh, we're doing math. I better change the subtype to a numeric one before I do the math, because I can't do math on Strings." This is pretty straightforward. What isn't so straightforward is that it chose the Double subtype instead of Long or Integer or Bytes.

We may never know the exact reason why VBScript chooses a Double in this situation, but it is probably a prevention measure. Other than the Decimal subtype, which is rarely used and only then for extremely large or extremely small number, the Double subtype is the most capable of holding large numbers. Rather than go to the trouble of figuring out the result of the math first, and then deciding on a subtype, VBScript just picks the most accommodating subtype, Double, so that it can be reasonably sure that the result of the math will fit in the variable. In other words, VBScript makes the safest choice.

First

Next