Placing New Value

A Variant variable automatically chooses its subtype whenever you place a new value into it. It does this by examining the value placed into and making its best guess as to what the appropriate subtype is. Sometimes, though, the Variant’s “best guess” is not quite what you expect. However, you can control this by being careful and explicit in your code. Let’s look at some code example that will demonstrate the principles that I have been talking about here.

Dim varTest
varTest = "Hello There"
MsgBox TypeName(varTest)

This makes sense. I placed a text (a.k.a. "string") value into the variable varTest, and VBScript appropriately decided that the variable should have the String subtype.

First
Next