码迷,mamicode.com
首页 > 编程语言 > 详细

VBA算术运算符

时间:2019-08-13 20:09:43      阅读:92      评论:0      收藏:0      [点我收藏+]

标签:width   double   bsp   idt   private   const   click   变量   整数   

假设变量A=5,变量B=10,那么 -

运算符描述示例
+ 两个操作数相加 A + B = 15
- 两个操作数相减 A - B = -5
* 两个操作数相乘 A * B = 50
/ 两个操作数相除 B / A = 2
% 模运算符,整数除法后的余数 B % A = 0
^ 指数运算符 B ^ A = 100000

示例

添加一个按钮并尝试下面的示例来了解如何在VBA中使用算术运算符。

Private Sub Constant_demo_Click()
   Dim a As Integer
   a = 5

   Dim b As Integer
   b = 10

   Dim c As Double

   c = a + b
   MsgBox ("Addition Result is " & c)

   c = a - b
   MsgBox ("Subtraction Result is " & c)

   c = a * b
   MsgBox ("Multiplication Result is " & c)

   c = b / a
   MsgBox ("Division Result is " & c)

   c = b Mod a
   MsgBox ("Modulus Result is " & c)

   c = b ^ a
   MsgBox ("Exponentiation Result is " & c)
End Sub

当点击按钮或执行上面的脚本时,会产生类似下面的结果。

Addition Result is 15

Subtraction Result is -5

Multiplication Result is 50

Division Result is 2

Modulus Result is 0

Exponentiation Result is 100000

 

 

VBA算术运算符

标签:width   double   bsp   idt   private   const   click   变量   整数   

原文地址:https://www.cnblogs.com/sunyllove/p/11348068.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!