VBA 不为空
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/702614/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
VBA Not IsNull
提问by Terry
Working with some VBA code in Access that when a very specific set of conditions are met it will pop up an InputBox asking for a integer. So far so good.
在 Access 中使用一些 VBA 代码,当满足一组非常具体的条件时,它会弹出一个 InputBox,要求输入一个整数。到现在为止还挺好。
Private Sub Command10_Click()
If Not IsNull(mrf) Then
If min <> max Then
If qty <= min Then
mrf = GetParamValue
End If
End If
End If
End Sub
The problem is that the Not IsNull seems to be ignored. I would like it to ask for a value to be entered unless a value is already present. This keeps firing off the InputBox as long as the min <> max and qty <= min conditions are met. What am I missing here?
问题是 Not IsNull 似乎被忽略了。我希望它要求输入一个值,除非值已经存在。只要满足 min <> max 和 qty <= min 条件,就会不断触发 InputBox。我在这里缺少什么?
回答by GSerg
If mrfis Variant, then it's initially Empty, not Null. You therefore have to use IsEmpty()function.
如果mrf是 Variant,那么它最初是Empty,而不是Null。因此,您必须使用IsEmpty()函数。
回答by Stephen Wrighton
No, the Not IsNullis working perfectly.
不,Not IsNull工作正常。
Remember, IsNullis a function which returns TRUE if the parameter passed to it is null, and false otherwise.
请记住,IsNull是一个函数,如果传递给它的参数为 null,则返回 TRUE,否则返回 false。
Your "If Not IsNull(mrf) Then" statement translates into english as "If mrf is not null then"
您的“If Not IsNull(mrf) Then”语句翻译成英文为“If mrf is not null then”
what that means is when mrf has a value, then you're processing the code inside the if statement. If you're wanting the inner code to fire when mrf IS null, then you need to remove the NOTfrom the statement.
这意味着当mrf 具有值时,您正在处理if 语句中的代码。如果您希望在 mrf 为空时触发内部代码,那么您需要从语句中删除NOT。
回答by Dan Coates
My guess is that mrf isn't null, even if it's empty or something else. It could also be Nothing, which is different from null in VBA land (I think). Try running the code in the debugger and looking at the value of mrf. Depending on what mrf is, you can do a different test (like check len(mrf) or not isNothing(mrf) or if it's an integer, and it's init to zero, then mrf <> 0.... you get the idea. Hope that helps!
我的猜测是 mrf 不为空,即使它是空的或其他东西。它也可能是 Nothing,这与 VBA 领域中的 null 不同(我认为)。尝试在调试器中运行代码并查看 mrf 的值。根据 mrf 是什么,你可以做一个不同的测试(比如检查 len(mrf) 或不是 isNothing(mrf) 或者它是一个整数,它初始化为零,然后 mrf <> 0 .... 你明白了. 希望有帮助!
回答by Lunatik
You might be interested in this piece on VB6/VBA null/nothing/empty:
您可能对 VB6/VBA null/nothing/empty 上的这篇文章感兴趣:
http://blogs.msdn.com/ericlippert/archive/2003/09/30/53120.aspx
http://blogs.msdn.com/ericlippert/archive/2003/09/30/53120.aspx

