vba逻辑运算符分组

时间:2018-07-12 06:15:59

标签: excel vba excel-vba

基本上我想要否定(NOR)

在vba中,我想在if语句中实现以下逻辑分组:

x1 or x2 or x3 or <SPAN STYLE="text-decoration:overline">x4 or x5</SPAN>

前三个条件仅与或连接。最后两个条件应首先使用或进行求值,然后取反。

到目前为止,我尝试过:

x1 or x2 or x3 or not (x4 or x5)

但这似乎不起作用。

示例:

IF textbox1 = "" or textbox2 = "" or textbox3 = "" or not (option1 = false
or option2 = false) 

基本上我想要否定(NOR)

0 0 -> 1
0 1 -> 0
1 0 -> 0
1 1 -> 0

2 个答案:

答案 0 :(得分:1)

x4和x5是否应该是组合逻辑?因此,此比较的结果应该是x1,x2和x3的较大逻辑的布尔值?

您可能打算表示:

x1 or x2 or x3 or (x4 and x5)

这种方式:如果x4或x5为假,它将返回为假。

答案 1 :(得分:1)

实际上不是答案,但希望有帮助的代码使您走得更远:

Sub Logicals()
    Dim x1 As Boolean, x2 As Boolean, x3 As Boolean, x4 As Boolean, x5 As Boolean

    If x1 Or x2 Or x3 Or Not (x4 Or x5) Then MsgBox "Got it" ' prompts the message "Got it", since x1, x2, and x3 are False by default and Not (x4 Or x5) = True (being both x4 and x5 False)


    x4 = True ' the same with x5 = True
    If x1 Or x2 Or x3 Or Not (x4 Or x5) Then MsgBox "Got it" ' doesn't prompt the message "Got it" since x1, x2, and x3 are False by default and Not (x4 Or x5) = False (being x4 True)

End Sub
相关问题