“Null"和“Null"有什么区别?和“没什么"在VB6中? [英] What is the difference between "Null" and "Nothing" in VB6?

查看:29
本文介绍了“Null"和“Null"有什么区别?和“没什么"在VB6中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个这样的记录集:

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 wrong!
    If rs.State <> adStateClosed Then rs.Close
    Set rs = Nothing
end if

' I want to evaluate if rs is Nothing, or Null

if rs is Nothing then 
' this doesn't throw errors, and works well :D
end if

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

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

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

我发现在 VB6 中我很少使用Null"(我用它来评估空记录集模式名称),但我使用Nothing"来表示图像、adodb.connections 或记录集等内容.对于字符串,我有 vbNullString.我读到它是一个指向空字符串的指针.

I found out that in VB6 I rarely use "Null" (I used it for evaluating empty recordset schema names), but I use "Nothing" for stuff like images, adodb.connections or recordsets. For strings I have vbNullString. I read it is a pointer to a null string.

Null"是否像未知变量值"而Nothing"是真正的空值?

Is "Null" like a "unknown variable value" and "Nothing" a true null value?

推荐答案

Null 是 Variant 的特定子类型.它在 Variant 类型之外不存在,创建它是为了允许 Variant 为数据库空值建模.

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 是 Object 变量的值.它本质上与空指针相同,即没有对象.

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

以下会引发错误,因为Is"只能与对象变量一起使用:

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

以下会引发错误,因为 Object 变量永远不能为 Null:

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

以下计算结果为 False,因为 IsNull() 采用 Variant 参数.

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

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

相当于:

VarType(rs) = vbNull

这篇关于“Null"和“Null"有什么区别?和“没什么"在VB6中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆