Null and Nothing
Hi,
I have a simple question:
What is the difference between Null and Nothing
and what is the syntax for using them,
Thanks,
Tal.
[149 byte] By [
yaarital] at [2007-11-17 17:06:50]

# 1 Re: Null and Nothing
The simplest answer to this is that NULL is a value and NOTHING is a state.
The Null Value
The Variant data type can contain another special value: Null. Null is commonly used in database applications to indicate unknown or missing data. Because of the way it is used in databases, Null has some unique characteristics:
Expressions involving Null always result in Null. Thus, Null is said to "propagate" through expressions; if any part of the expression evaluates to Null, the entire expression evaluates to Null.
Passing Null, a Variant containing Null, or an expression that evaluates to Null as an argument to most functions causes the function to return Null.
Null values propagate through intrinsic functions that return Variant data types.
You can also assign Null with the Null keyword:
Z = Null
You can use the IsNull function to test if a Variant variable contains Null:
If IsNull(X) And IsNull(Y) Then
Z = Null
Else
Z = 0
End If
If you assign Null to a variable of any type other than Variant, a trappable error occurs. Assigning Null to a Variant variable doesn't cause an error, and Null will propagate through expressions involving Variant variables (though Null does not propagate through certain functions). You can return Null from any Function procedure with a Variant return value.
Variables are not set to Null unless you explicitly assign Null to them, so if you don't use Null in your application, you don't have to write code that tests for and handles it.
Other data types cannot handle NULL values.
When you instantiate an object such as a class whether it be a user-defined class or an object such as an ADODB.Connection object, you obtain a reference to the object itself. You then use the syntax:
Set objObjectRef = Nothing
To destroy that reference (and depending on the object the object itself).
# 2 Re: Null and Nothing
My understanding of the two is that null applies to a field, and nothing applies to an object.
If a field contains a null value, it contains nothing not even spaces. An object that has been set to nothing is released from memory.
examples of use of null:
If ISNULL(fld) then
if txtbox = "" then
fld = null
endif
Examples of use of nothing:
set adoconnection = new adodb.connection
...
....
...
set adoconnection = nothing
# 5 Re: Null and Nothing
I didn't say that "" = null, but in alot of our applications, if a user has entered nothing into a text box, we set the database field to null - this way, we don't get referential integrity problems.