加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

VB6中“Null”和“Nothing”有什么区别?

发布时间:2020-12-17 00:04:17 所属栏目:大数据 来源:网络整理
导读:我有一个这样的记录集: Dim rs as RecordsetSet 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 = Nothingend if' I want to evaluate if rs is Nothing,
我有一个这样的记录集:
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”(我用它来评估空记录集模式名称),但我对图像,adodb.connections或记录集之类的东西使用“Nothing”.对于字符串我有vbNullString.我读到它是一个指向空字符串的指针.

“Null”是“未知变量值”而“Nothing”是真正的空值吗?

Null是Variant的特定子类型.它不存在于Variant类型之外,并且创建它以允许Variant为数据库null值建模.

没有什么是Object变量的值.它基本上与空指针相同,即没有对象.

以下引发错误,因为“Is”只能与Object变量一起使用:

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

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

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

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

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

它相当于:

VarType(rs) = vbNull

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读