Double Subtype - ONE

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

However, does it really matter that VBScript coerced the variable into Double instead of a Long? There are both numeric subtypes, and the math has exactly the same result. Why care? Well, it's not the end of the world, except that the Double subtype theoretically takes a little bit more processing power than the Long, because the Double is a floating point, numeric subtype (floating point numbers require a greater degree of accuracy, and therefore the processor has to work a little harder to ensure that accuracy). If you were explicitly coercing the subtype, as in the code I started with, you might not choose the Double, because the Double is generally only used for very large or small numbers. You might choose Integer, or Long, or even Byte. That said, sometimes you need to care what the subtype is because you are planning to pass the variable to a method of a COM object that expects an explicit subtype.

The point of this little exercise is not to debate one numeric subtype is better than another, rather to illustrate implicit type coercion. VBScript automatically knew that we wanted the value the variable to be a number.

First
Next