我有一个这样的记录集:
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值建模.
原文链接:https://www.f2er.com/vb/255837.html没有什么是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