搜档网
当前位置:搜档网 › null及empty的区别

null及empty的区别

SELECT sum(table_zongbiao.金额)
FROM table_zongbiao
HAVING (((Left(table_zongbiao.[发注NO],2))="SD") AND ((table_zongbiao.[入账分类])="办公费用") AND ((table_zongbiao.[向别])="共通") AND ((Year(table_zongbiao.[纳入日期]))=2010) AND ((Month(table_zongbiao.[纳入日期]))=3));


IsEmpty ( 变数 )测试变量是 (True) 否 (False) 已经被初始化例子: IsEmpty (a)
结果: True

IsNull ( 变数 )测试变数是 (True) 否 (False) 不是有效的数据。例子: IsNull ("")
结果: False


dim num
num = null ' ? 问题1: NULL的值是什么, 问题2:= null 的作用是什么
num = empty ’ ? 问题1: empty 的值是什么? 问题2:= empty 的作用是什么

最后一个问题,变量初始化的具体过程是什么,是以下过程吗:
1、给变量分配内存
2、给内存赋值。
3、在操作系统管理的变量管理表中添加此变量名称和他所指向的内存地址,应该还包含,内存的字节数。

这样lz更便于理解
****************
经过以下的叙述之后, 变量 A、B、C、D 分别等于 0、""、Null、 Empty、 Nothing 的哪一个?
Dim A
Dim B As String
Dim C As Integer
Dim D As Object
A 等于 Empty, 因为尚未初始化的「不定型变量」都等于 Empty。但如果检测 A = "" 或 A = 0, 也都可以得到 True 值。
B 等于 "", 因为尚未初始化的非固定长度「字串」都等于 "" 。 但请注意 B<> Null。
C 等于 0, 这个很简单,没问题吧?
D 等于 Nothing, 尚未设定有物件的「物件变量」都等于 Nothing, 但请不要使用 D = Nothing , 而要使用 D Is Nothing 来判断 D 是否等于 Nothing, 因为判断 是否相等的符号是 Is 不是 = 。
最令人迷惑的地方是 Null 这个保留字, 请看以下语句:
Print X = Null
Print X <> Null
结果都是输出 Null(不是 True 也不是 False), 这是因为任何一个运算式只要含有 Null , 则该运算式就等于 Null, 实际上想要判断某一数据是否为 Null 绝对不能使用:
If X = Null Then ' 永远都会得到 Null
而要使用:
If IsNull(X) Then
哪一种数据会等于 Null 呢? 除了含有 Null 运算式之外, 就属没有输入任何数据的「数据字段」(在数据库中) 会等于 Null。


isempty() 针对variant 类型
isnull() 指出表达式是否不包含任何有效数据


IsNull 函数


返回 Boolean 值,指出表达式是否不包含任何有效数据 (Null)。



If IsNumeric(Me.Text23) = True And IsNumeric(Me.Text48) = True Then
Me.Text72 = Me.Text23 / Me.Text48
End If

If IsNumeric(Me.Text24) = True And IsNumeric(Me.Text47) = True Then
Me.Text72 = Me.Text24 / Me.Text47
End If

If IsNumeric(Me.Text25) = True And IsNumeric(Me.Text47) = True Then
Me.Text72 = Me.Text25 / Me.Text47
End If

If IsNumeric(Me.Text26) = True And IsNumeric(Me.Text47) = True Th

en
Me.Text72 = Me.Text26 / Me.Text47
End If

If IsNumeric(Me.Text27) = True And IsNumeric(Me.Text47) = True Then
Me.Text72 = Me.Text27 / Me.Text47
End If

If IsNumeric(Me.Text28) = True And IsNumeric(Me.Text47) = True Then
Me.Text72 = Me.Text28 / Me.Text47
End If

If IsNumeric(Me.Text29) = True And IsNumeric(Me.Text47) = True Then
Me.Text72 = Me.Text29 / Me.Text47
End If

If IsNumeric(Me.Text30) = True And IsNumeric(Me.Text47) = True Then
Me.Text72 = Me.Text30 / Me.Text47
End If

If IsNumeric(Me.Text31) = True And IsNumeric(Me.Text47) = True Then
Me.Text72 = Me.Text31 / Me.Text47
End If

If IsNumeric(Me.Text32) = True And IsNumeric(Me.Text47) = True Then
Me.Text72 = Me.Text32 / Me.Text47
End If

If IsNumeric(Me.Text33) = True And IsNumeric(Me.Text47) = True Then
Me.Text72 = Me.Text33 / Me.Text47
End If

If IsNumeric(Me.Text34) = True And IsNumeric(Me.Text47) = True Then
Me.Text72 = Me.Text34 / Me.Text47
End If

If IsNumeric(Me.Text35) = True And IsNumeric(Me.Text47) = True Then
Me.Text72 = Me.Text35 / Me.Text47
End If

If IsNumeric(Me.Text36) = True And IsNumeric(Me.Text47) = True Then
Me.Text72 = Me.Text36 / Me.Text47
End If

If IsNumeric(Me.Text37) = True And IsNumeric(Me.Text47) = True Then
Me.Text72 = Me.Text37 / Me.Text47
End If

语法

IsNull(expression)

必要的 expression 参数是一个 Variant,其中包含数值表达式或字符串表达式。

说明

如果 expression 为 Null,则 IsNull 返回 True;否则 IsNull 返回 False。如果 expression 由多个变量组成,则表达式的任何作为变量组成成分的 Null 都会使整个表达式返回 True。

Null 值指出 Variant 不包含有效数据。Null 与 Empty 不同,后者指出变量尚未初始化。Null 与长度为零的字符串 (““) 也不同,长度为零的字符串指的是空串。

重要 使用 IsNull 函数是为了确定表达式是否包含 Null 值的。在某些情况下,希望表达式取值为 True,比如希望 If Var = Null 和 If Var <> Null 取值为 True,而它们总取值为 False。这是因为任何包含 Null 的表达式本身就是 Null,所以为 False。

IsEmpty 函数


返回 Boolean 值,指出变量是否已经初始化。

语法

IsEmpty(expression)

必要的 expression 参数是一个 Variant,包含一个数值或字符串表达式。但是,因为 IsEmpty 被用来确定个别变量是否已初始化,所以 expression 参数通常是单一变量名。

说明

如果变量未初始化或已明确设置为 Empty,则 IsEmpty 返回 True;否则返回 False。如果 expression 含有多个变量,则 IsEmpty 总是返回 False。IsEmpty 只返回对 variant 表达式有意义的信息。

相关主题