• VBA连接操作符


    VBA支持以下连接运算符。

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

    运算符描述示例
    + 将两个值添加为变量,其值是数字 A + B = 15
    & 连接两个值 A & B = 510

    示例1

    试试下面的例子来理解VBScript中可用的连接运算符 -

    Private Sub Constant_demo_Click()
       Dim a as Integer : a = 5
       Dim b as Integer : b = 10
       Dim c as Integer
    
       c = a + b  
       msgbox ("Concatenated value:1 is " &c) 'Numeric addition 
    
       c = a & b 
       msgbox ("Concatenated value:2 is " &c) 'Concatenate two numbers 
    End Sub

    执行上面示例代码,得到类似下面的结果 -

    Concatenated value:1 is 15
    
    Concatenated value:2 is 510
    Shell

    假设变量A = "Microsoft",变量B = "VBScript",则 -

    运算符描述示例
    + 连接两个值 A + B 的结果为MicrosoftVBScrip
    & 连接两个值 A & B 的结果为MicrosoftVBScrip

    注 - 连接操作,可用于数字和字符串。输出取决于上下文,如果变量保存数字值或字符串值。

    示例2

    尝试下面的示例,通过创建一个按钮并添加以下函数来了解VBA中可用的所有逻辑运算符。

    Private Sub Constant_demo_Click()
       Dim a as String : a = "Microsoft"
       Dim b as String : b = "VBScript"
       Dim c as String
    
       c = a + b 
       msgbox("Concatenated value:1 is " &c) 'addition of two Strings
    
       c = a & b 
       msgbox("Concatenated value:2 is " &c) 'Concatenate two String
    End Sub

    执行上面示例代码,得到类似下面的结果 -

    Concatenated value:1 is MicrosoftVBScript
    
    Concatenated value:2 is MicrosoftVBScript
  • 相关阅读:
    CentOS 7 安装MySQL 5.7
    Introduction to BGP (4)
    Introduction to BGP (3)
    Introduction to BGP (2)
    Introduction to BGP (1)
    Cisco NAT Fundation
    Linux安装Nginx
    GRE协议学习与练习
    Oracle Study Note : Users and Basic Security
    Oracle Study Note : Tablespace and Data Files
  • 原文地址:https://www.cnblogs.com/sunyllove/p/11348095.html
Copyright © 2020-2023  润新知