美文网首页
VBA的运算符号

VBA的运算符号

作者: iOS大熊猫 | 来源:发表于2024-03-25 10:38 被阅读0次

    常规数学运算符: + - * / ^
    特殊数学运算符: \ 整除 mod 取余数
    其他运算符: & ()

    比较运算符: =赋值 < > <= >=
    特殊比较符: is like

    逻辑运算符 : and or xor not
    Xor同假异真 Eqv同真异假 Imp 先真后假才为真

    XOR 逻辑排除。它是NOT和OR运算符的组合。如果表达式中只有一个表达式的值为True,则结果为True。表示两者不同时为真,相同时为假
    EQV,表示两者相同是为真,不同是为假
    imp逻辑蕴含

    'Sub 计算测试()
     
    Dim arr1(30)
     
    arr1(0) = 99
    arr1(1) = 1 + 2
    arr1(2) = 2 - 1
    arr1(3) = 3 * 5
    arr1(4) = 10 / 3       '除法
    arr1(5) = 10 \ 3       '整除
    arr1(6) = 10 Mod 3     '去余数
    arr1(7) = (1 + 3) / 2
    arr1(11) = "a" & "b"
    arr1(12) = "a" + "b"     '字符串可以相加
    arr1(13) = 1 >= 2
    arr1(14) = 1 <= 2
    arr1(15) = (1 = 2)
    arr1(16) = (1 = 1)
     
     
    Dim a As Object
    Dim b As Object
    Dim c As Object
    Set a = b
     
    arr1(17) = a Is b        'is只能用于比较对象是否完全一样
    arr1(18) = Not a Is b
    arr1(19) = a Is c        '因为a,b,c 都是空对象,可以相等
     
    arr1(21) = "test1.xlsm" Like "*.xlsm"    'like 比较需要 ""之内的内容
    arr1(22) = (1 > 2) And (1 < 2)
    arr1(23) = (1 > 2) Or (1 < 2)
    arr1(30) = (1 > 2) Eqv (1 < 2)
    'arr1(31) = True Eqv True
    'arr1(32) = 1 Eqv 2
    'arr1(33) = 1 Eqv 1
     
    'arr1(34) = (1 > 2) Xor (1 < 2)
    'arr1(35) = (1 > 2) Xor (1 > 2)
    'arr1(36) = 1 Xor 2
    'arr1(37) = 1 Xor 1
     
     
    'arr1(38) = (3 > 2) Imp (5 > 2)    '逻辑包含关系
    'arr1(39) = (1 < 2) Imp (1 < 3)
    'arr1(40) = (1 < 2) Imp (1 < 2)
     
     
     
    For i = LBound(arr1) To UBound(arr1)
        Debug.Print "arr1(" & i & ")= " & arr1(i)
    Next
     
     
    End Sub
    

    运算结果

    arr1(0)= 99
    arr1(1)= 3
    arr1(2)= 1
    arr1(3)= 15
    arr1(4)= 3.33333333333333
    arr1(5)= 3
    arr1(6)= 1
    arr1(7)= 2
    arr1(8)= 
    arr1(9)= 
    arr1(10)= 
    arr1(11)= ab
    arr1(12)= ab
    arr1(13)= False
    arr1(14)= True
    arr1(15)= False
    arr1(16)= True
    arr1(17)= True
    arr1(18)= False
    arr1(19)= True
    arr1(20)= 
    arr1(21)= True
    arr1(22)= False
    arr1(23)= True
    arr1(24)= 
    arr1(25)= 
    arr1(26)= 
    arr1(27)= 
    arr1(28)= 
    arr1(29)= 
    arr1(30)= False
    

    相关文章

      网友评论

          本文标题:VBA的运算符号

          本文链接:https://www.haomeiwen.com/subject/anpdtjtx.html