Why does this string need to be declared as an object when comparing to Nothing?
Dim BlankStr
BlankStr = "blank"
If BlankStr Is Nothing Then
End If
I also cannot compare If 1 Is 1 Then. Why can't I compare primitives?
Why does this string need to be declared as an object when comparing to Nothing?
Dim BlankStr
BlankStr = "blank"
If BlankStr Is Nothing Then
End If
I also cannot compare If 1 Is 1 Then. Why can't I compare primitives?
VBScript has data (sub) types. Besides simple (sub) types like Strings:
>> x = "blank"
>> WScript.Echo VarType(x), TypeName(x)
>>
8 String
there are Objects:
>> Set y = New RegExp
>> WScript.Echo VarType(y), TypeName(y)
>>
9 IRegExp2
To assign an object to a variable, you need Set, to compare objects, you need Is. Simple (non-object) values have their own comparison operator.
To compare a string against another:
>> WScript.Echo CStr(x = "blank"), CStr(x = "object")
>>
True False
Trying to use a simple value 'as if it were an object', throws an "object required" error:
>> Set z = "blank"
>>
Error Number: 424
Error Description: Object required
>> WScript.Echo CStr(x Is x)
>>
Error Number: 424
Error Description: Object required
Read A Whole Lot Of Nothing.
According a comment to this answer, VBScript doesn't have a string type. Instead it sounds like strings are primitives. Is works with object references.