Another Coercion Example

Run the following code in Windows Script Host:

Dim intTest
intTest = CInt(100)
MsgBox "TypeName after initialization to 100: " & _
intTest = intTest + 1000000
MsgBox "TypeName after adding 1,000,000: " & _
intTest = intTest + 10000000000
MsgBox "TypeName after adding another 10,000,000,000: " & _

Notice that we initialized the variable with a value of 100, and use the CInt ( ) function to coerce the subtype into Integer. The first call to the TypeName ( ) function reflects String. Then we added 1,000,000 to the variable. The next call to the TypeName ( ) function reveals that VBScript coerced the subtype to Long. Why did it do this? Because we exceeded the upper limit of the Integer subtype, which is 32,767. VBScript will promote numeric subtype when the value exceeds the upper or lower limits of the current numeric subtype. Finally, we add another ten billion to the variable. This exceeds the upper limit of the Long subtype, so VBScript upgrades the subtype to Double.