What is the difference between “Null” and “Nothing” in VB6?

后端 未结 3 2004
悲哀的现实
悲哀的现实 2020-12-17 20:39

I have a recordset like this:

Dim rs as Recordset
Set rs as New Recordset

\'... a lot of coding ...

if Err.Number <> 0 Then \' oops, something gone w         


        
3条回答
  •  盖世英雄少女心
    2020-12-17 21:29

    Null is a specific subtype of a Variant. It has no existence outside of the Variant type, and is created to allow a Variant to model a database null value.

    Nothing is a value of an Object variable. It essentially is identical to a null pointer, i.e. there is no object.

    The following raises an error because "Is" can only be used with Object variables:

    if rs is Null then
    ' this throws an error of "types not compatible"
    end if
    

    The following raises an error because an Object variable can never be Null:

    if rs = Null then
    ' this throws an error of "types not compatible"
    end if
    

    The following evaluates False because IsNull() takes a Variant argument.

    if isNull(rs) then
    ' never enters here, isNull(rs) evaluates to False
    end if
    

    It is equivalent to:

    VarType(rs) = vbNull
    

提交回复
热议问题