Quote:
Null Strings and Null Characters
To its credit, VB does allow null BSTRs. The code:
Dim s As String
s = vbNullString
Debug.Print VarPtr(s)
Debug.Print StrPtr(s)
produces the following output (your address may vary, of course):
1243948
0
This shows that a null BSTR is simply a pointer whose contents are 0. (We will discuss the meaning of StrPtr in a moment.) In Win32 and VC++, this is called a null pointer. You can probably see the difference between vbNullString and vbNullChar at this point. vbNullChar is not a pointer--it is a Unicode character whose value is 0. Thus, at the bit level, the values vbNullString and vbNullChar are identical. However, they are interpreted differently, so they are in fact different.
It is also important not to confuse a null BSTR with an empty BSTR, usually denoted by a pair of adjacent quotation marks:
Dim s As String
Dim t As String
s = vbNullString
t = ""
Unlike a null string, the empty BSTR t is a pointer that points to some nonzero memory address. At that address resides the terminating null character for the empty BSTR, and the preceeding length field also contains a 0.