vbNull and vbNullString

vbNull is like an enumeration for VarType. (Pedantically speaking it is not an enumeration because it isn't an argument of a function or a sub but a result. However it does the same job.)

These following are both the same test but the vbNull is easier than remembering all the different numbers for variable type (vbEmpty, vbInteger, vbLong, etc)

VarType(somevariable) = 1
VarType(somevariable) = vbNull

It is the same with all enumerations. The code is actually working on numbers. The enumerations are for our convenience.

For example, when you open a recordset you might specify dbReadOnly which enumerates to 4.

vbNullString is just another way to write "" more clearly when "" can get lost in the code.
 
Thanks for this clarification.

The names are still doesn't make sense to me.
When they say Null I expect NULL, not an EmptyString nor 1.

I'm sure won't use vbNull when I look for 1.
Why should I check for the VarType() of a variable I declared before ?

using vbNullString to replace the "" make sense when "" can get lost in the code.
 
When they say Null I expect NULL, not an EmptyString nor 1

These constant names are based on the name of the variable type not their content. Do you expect everyone in your surname fields to be called Mr Surname?:rolleyes:

The variable type itself is represented by a number in the internal processing and is what the VarType function returns.

You can use TypeName() instead if you like but then you have to remember the exact name. It also uses a lot more processing than VarType() in the days when anyone cared about that.

Why should I check for the VarType() of a variable I declared before ?

You could declare a variable as a variant then give it a value.

VarType() will return the actual type it holds.

It can be used for testing the potential casting of a variant value to another variable type.
 
As you can use these also to put data into the variable and not only to test it's varType it can be confusing.

Let's agree not to totally agree about this issue :)
 
You can also put data in using any of the enumerations in Access. This will put 4 into the variable but you wouldn't use it either.

intWhatever = dbReadOnly

Just because something resolves to a value it doesn't mean you would use it. If it doesn't resolve to what you expect then you should question your understanding rather than the workings of the program.

There is no confusion if you understand the principles involved.
 

Users who are viewing this thread

Back
Top Bottom