excel - 为什么在“或”不起作用时“与”在这里起作用?
问题描述
在我的情况下,使用 OR 不起作用,我必须使用 AND,我不知道为什么。
Sub blah()
If LCase(Environ("username")) <> "me" Or LCase(Environ("username")) <> "some other user" Then '''DOESN'T WORK
Stop
ElseIf LCase(Environ("username")) <> "me" And LCase(Environ("username")) <> "some other user" Then '''WORKS
Stop
End If
End Sub
解决方案
您的示例很难理解,但您可能只是对运算符的性质感到困惑。
想想真值表;操作的结果Or
是True
如果至少有一个操作数是True
:
True Or True => True
True Or False => True
False Or True => True
False Or False => False
同样,如果两个操作数都是,则And
运算的结果是:True
True
True And True => True
True And False => False
False And True => False
False And False => False
如果有帮助,您可以将其可视Or
化为+
(加法)和And
(*
乘法)运算,其中False
存在0
和True
“不为零”:
1 Or 1 => 1 + 1 => True
1 Or 0 => 1 + 0 => True
0 Or 1 => 0 + 1 => True
0 Or 0 => 0 + 0 => False
1 And 1 => 1 * 1 => True
1 And 0 => 1 * 0 => False
0 And 1 => 0 * 1 => False
0 And 0 => 0 * 0 => False
推荐阅读
- excel - 如何在excel(2016)中为整列左侧添加小数,并将整列向上添加112 = 1.12
- php - 使验证成为 laravel 中的唯一整数输入
- elasticsearch - 如何在 Elasticsearch 中查找包含给定点的多边形
- html - HTML 表单:Datalist 选项标记文本不从右到左更改
- reactjs - 如何在 React 中为 2 个相同的子组件分配不同的值
- python - Python. The way how to find out the element's order based on selected variable in list
- scala - 如何在火花数据框中明智地访问元素列
- rubygems - Ruby gem 的反向移植补丁
- python - python-使用底图在给定坐标处绘制热图
- php - Php Ziparchive extractTo 方法不提取 zip 文件