VBScript is typeless, so type mismatch is always an issue.
If you need to define the variable before you pass it, or after, then format the variable like this:
'=========================================
stMyVariable = "My text or number value here"
WScript.Echo CStr(stMyVariable)
'=========================================
CStr converts the variable contents to a string. If the value is null, however, then you will get an error. Perhaps this:
'=========================================
If stMyVariable <> "" Then
WScript.Echo CStr(stMyVariable)
Else stMyVariable = "Null"
WScript.Echo CStr(stMyVariable)
End If
'=========================================
Likewise CInt converts to Integer, and CDate converts a valid date/time to Date, CBool converts to Boolean, CByte converts to Byte, CCur = Currency, CDbl = Double, CLng = Long, CSng = Single, Hex returns Hex value, Oct returns Octal value, and Chr converts ANSI to a character.
So with all these available types that VBScript has to guess at, it is sometimes best to force the type yourself to make sure there are no problems with type mismatch. I use these a lot in my code.
mmcdonal
|