2007年7月28日 星期六

1.7 Operators: +-*/\^, Mod, And, Or, Not, =>< <>...

Private Sub VBA_Operators()

Dim a, b As Integer
Dim c, d, e As Boolean
c = True
d = False
a = 10
b = 3

'MsgBox "a+b=" & (a + b)
'MsgBox "a-b=" & (a - b)
'MsgBox "a*b=" & (a * b)
'MsgBox "a/b=" & (a / b)
MsgBox "a\b=" & (a \ b)
'MsgBox "次方 a^b=" & (a ^ b)
'MsgBox "餘數 a mod b=" & (a Mod b)
MsgBox "兩樣同時符合 c and d=" & (c And d)
MsgBox "c or d=" & (c Or d)
MsgBox "Not c is" & (Not c)
'MsgBox "a=b" & (a = b)
'MsgBox "a<b" & (a < b)
'MsgBox "a>b" & (a > b)
'MsgBox "a<=b" & (a <= b)
'MsgBox "a>=b" & (a >= b)
'MsgBox "a<>b=" & (a <> b)

End Sub

  1. \ 除後排除小數點。 10.6 -> 10
  2. ^ 次方。 ^(1/2) 開方
  3. Mod 餘數
  4. And 符合兩個條件。True And False -> False
  5. Or 符合其中一個條件。True And False -> True
  6. Not 相反。 Not True -> False
  7. <> 不等於

沒有留言: