zoukankan      html  css  js  c++  java
  • VBA比较运算符

    VBA支持的比较运算符如下所示。

    假设变量A=10,变量B=20,则 -

    运算符描述示例
    = 检查两个操作数的值是否相等。如果是,那么条件是真。 (A = B)结果为:False
    <> 检查两个操作数的值是否不相等。如果值不相等,则条件为真。 (A <> B)结果为:True
    > 检查左操作数的值是否大于右操作数的值。如果是,那么条件是真。 (A > B)结果为:False
    < 检查左操作数的值是否小于右操作数的值。如果是,那么条件是真。 (A < B)结果为:True
    >= 检查左操作数的值是否大于或等于右操作数的值。 如果是,那么条件是真。 (A >= B)结果为:False
    <= 检查左操作数的值是否小于或等于右操作数的值。如果是,那么条件是真。 (A <= B)结果为:True

    示例

    尝试以下示例以了解VBA中可用的所有比较运算符。

    Private Sub Constant_demo_Click()
       Dim a: a = 10
       Dim b: b = 20
       Dim c
    
       If a = b Then
          MsgBox ("Operator Line 1 : True")
       Else
          MsgBox ("Operator Line 1 : False")
       End If
    
       If a<>b Then
          MsgBox ("Operator Line 2 : True")    
       Else
          MsgBox ("Operator Line 2 : False")    
       End If
    
       If a>b Then
          MsgBox ("Operator Line 3 : True")    
       Else
          MsgBox ("Operator Line 3 : False")    
       End If
    
       If a<b Then
          MsgBox ("Operator Line 4 : True")    
       Else
          MsgBox ("Operator Line 4 : False")    
       End If
    
       If a>=b Then
          MsgBox ("Operator Line 5 : True")    
       Else
          MsgBox ("Operator Line 5 : False")    
       End If
    
       If a<=b Then
          MsgBox ("Operator Line 6 : True")
       Else
          MsgBox ("Operator Line 6 : False")
       End If
    
    End 

    当执行上面的脚本时,会产生类似下面的结果。

    Operator Line 1 : False
    
    Operator Line 2 : True
    
    Operator Line 3 : False
    
    Operator Line 4 : True
    
    Operator Line 5 : False
    
    Operator Line 6 : True
  • 相关阅读:
    手机的基本功能测试情景模式
    C#.net技术内幕04集合
    .net 发送电子邮件
    SQL:select case when(转)
    《 C#技术内幕》学习01IDisposable
    C#.net技术内幕03字符串
    点击确定后页面跳转
    SQL注入式攻击
    C#.NET技术内幕 02表达式
    window xp自带的功能之繁体字
  • 原文地址:https://www.cnblogs.com/sunyllove/p/11348080.html
Copyright © 2011-2022 走看看