vba是在等式比较中被视为零的空值 [英] vba are empty values treated as zeroes in equality comparison
问题描述
我正在尝试跳过具有零值或为空的记录。截至目前,我有以下代码明确地检查,但我觉得第二次检查是多余的。但我想确认我是对的,以便我可以删除IF的第二部分。
I am trying to skip records which either have a zero as the value or is empty. As of now, i have the following code that checks for both explicitly, but I feel that the second check is redundant. But I want to confirm that I am right so that I can remove the second part of the IF
IF (CellInValue(RowInCrnt, ColInCrnt) = 0 Or CellInValue(RowInCrnt, ColInCrnt) = "") Then
推荐答案
不,不等于
0
,并会在强类型中产生类型不匹配如果用作 Variant
,则不会出现平等。
No, ""
is not equal to 0
and will produce a type mismatch in a strongly typed scenario, or won't come out as equal if used as Variant
.
当单元格为空时,它是也不等于零,但它会相同,因为在VB中, Empty = 0
给出 True
因为隐式转换在后台发生。
相同于 Empty =
,还会给出 True
出于同样的原因。
When the cell is empty, it's also not the same as zero, but it will come out as same, because in VB, Empty = 0
gives True
because of implicit conversion happening in the background.
Same for Empty = ""
, will also give True
for the same reason.
所以你需要两个支票。
这篇关于vba是在等式比较中被视为零的空值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!