VBScript allows you to use the plus (+) operator to concatenate strings. However, this usage of plus (+) operator should be avoided. This is because the plus (+) operator, when used to concatenate strings, can cause unwanted implicit type coercion. Try this code:
Dim strFirst
Dim lngSecond
strFirst = CStr(50)
lngSecond = CLng(100)
MsgBox strFirst + lngSecond
The resulting dialogue box will display the number 150, which means that it added the two numbers mathematically rather than concatenating them. Now, this is admittedly a very silly example, but it illustrates that the plus (+) operator has different effects when you are not using it in a strictly mathematical context. The plus (+) operator uses the following rules when deciding what to do.
If both variables have the String subtype, the VBScript will concatenate the.
If both variables have any of the numeric subtype, then VBScript will add them.
If one of the variable has a numeric subtype, and the other has the String subtype, then VBScript will attempt to add them. If the variable with the String subtype does not contain a number, then a "Type Mismatch" error will occur.
Your best bet is to not worry about these rules and remember only the following:
Use the plus (+) operator only when you explicitly want to perform math on numeric values.
Always use the & operator to concatenate strings.
Never use the plus (+) operator to concatenate strings.
First