Null Delimited with Octothorpes and Null Propagation Returns "Null"

... # Null #
Whether "#" or "xyz" is used there is irrelevant. "#" is as String.
Code:
"String" + Null + "String" => Null
"String" & Null & "String" => "StringString"
 
I'm not certain that Null is a constant

It is according to the aforementioned reference document. Its definitional description is a bit vague (it's a bit pattern a variable descriptor) but its nature is crystal clear. It is treated as a constant and is recognized as such.

EDIT: Found the reference (just for the record). From the 24-Apr-2014 VBA Language Reference, paragraph 2.1, Data Values and Value Types, in the table on page 16/281, extracted from the table of value types, after the entry for Error and before the entry for Missing.

Null; A single distinguished value corresponding to the reserved identifier Null; An implementation specific bit pattern
 
Last edited:
Out of interest what would happen if you used a different variable type, other than a variant, as variant is very much a special case.
The thing is, only a Variant can contain Null.

Also, for this reason, Null propagation by use of the + operator wouldn't occur were a string variable to be concatenated similarly. If the string variable were uninitialized or expressly set to "" (i.e., a zero-length string) or vbNullString (i.e., its StrPtr = 0), the expression would resolve to "##"

The expression also doesn't evaluate a date literal.
 
@riktek : I didn't read all posts here yet, but regarding to your procedure in your opening post:

If I call it in the Immediate Window like this: `?TypeName(TestNullVariant())` it returns `Null`, so it definitely does not return a string, but type `Null`.
 
It is according to the aforementioned reference document. Its definitional description is a bit vague (it's a bit pattern a variable descriptor) but its nature is crystal clear. It is treated as a constant and is recognized as such.
I guess so. I just looked it up myself (Section 2.1): "A single distinguished value corresponding to the reserved identifier Null" represented as "An implementation specific bit pattern "

So, definitely a constant.

I wonder what the bit pattern is. Str(Null) also prints (not returns) Null and takes a Long argument, so I suppose that could mean Null is represented by a Long. Or not.
 
@riktek : I didn't read all posts here yet, but regarding to your procedure in your opening post:

If I call it in the Immediate Window like this: `?TypeName(TestNullVariant())` it returns `Null`, so it definitely does not return a string, but type `Null`.
Further through the responding posts, you'll see that the expression's return value is Null but it prints the string "Null" (without quotation marks) to the Immediate pane, instead of not printing anything.

Str(Null), Hex(Null), and Oct(Null) all do the same thing.
 
you'll see that the expression's return value is Null but it prints the string "Null" (without quotation marks) to the Immediate pane, instead of not printing anything.
Why would you expect an empty string instead of Null (text) for the output in the immediate window (<-- only for developer)?
I like the output Null as text better than an empty string for Null.

In principle, Debug.Print has something similar built in:
Code:
Public Function MyOwnDebugPrint(byval Value as Variant) as String
    if isnull(Value) then
        MyOwnDebugPrint = "Null"
    else 'implizit conversion to String
        MyOwnDebugPrint = Value
    end if
    ' or
    ' MyOwnDebugPrint = Nz(Value, "Null")
end Function
 
Last edited:
I guess so. I just looked it up myself (Section 2.1): "A single distinguished value corresponding to the reserved identifier Null" represented as "An implementation specific bit pattern "

So, definitely a constant.

I wonder what the bit pattern is. Str(Null) also prints (not returns) Null and takes a Long argument, so I suppose that could mean Null is represented by a Long. Or not.

It isn't anything. You said it yourself earlier - only a variant can be null. A variant is contained in a data descriptor, which describes everything you need to know about the variable. The value portion of a variant that is a null is never consulted because first you have to check the data type... which will say "oh, by the way, this is a null, don't bother looking for a value."

I have used descriptors in other environments. Access has maybe a couple of dozen variable-style data types that could be called out by the descriptor. There is even a descriptor for array types. The basic data type indicator in a descriptor is a byte, so you could have 256 choices. But you actually need little more than 1/10 of that number for variant variables.

However, Access uses the term "descriptor" more generically these days, since there are now file descriptors, graphics descriptors, security descriptors... their use has burgeoned since Win NT was first introduced.
 
Why would you expect an empty string instead of Null (text) for the output in the immediate window (<-- only for developer)?
Because that's what prints in every other case of Null.
 
It isn't anything. You said it yourself earlier - only a variant can be null. A variant is contained in a data descriptor, which describes everything you need to know about the variable. The value portion of a variant that is a null is never consulted because first you have to check the data type... which will say "oh, by the way, this is a null, don't bother looking for a value."

I have used descriptors in other environments. Access has maybe a couple of dozen variable-style data types that could be called out by the descriptor. There is even a descriptor for array types. The basic data type indicator in a descriptor is a byte, so you could have 256 choices. But you actually need little more than 1/10 of that number for variant variables.

However, Access uses the term "descriptor" more generically these days, since there are now file descriptors, graphics descriptors, security descriptors... their use has burgeoned since Win NT was first introduced.
I'm not programming at that level but that makes perfect sense. A variable has to be a data structure of some sort. A Null return based solely on a type evaluation would be computationally more efficient by gating address or value evaluation with a bitmask, which then also would provide a mechanism for type propagation.
 

Users who are viewing this thread

Back
Top Bottom