vb表达式求解
问题描述:
vb表达式求解
1、已经a=3,b=4,c=5
求a or b + c and b - c
2.、Not 4*(76-43)^2 and 5 0
答
'在窗体建一个命令按钮Command1
'1.
Private Sub Command1_Click()
Dim s, a, b, c As Integer
a = 3
b = 4
c = 5
s = a Or b + c And b - c
s1 = 3 Or 9 And -1
'算术运算符优先级最高,即表达式s=s1= 3 Or 9 And -1
'or和and同级按先后
'当and在两个数字中间时,and运算符就不是逻辑与运算符而是位与运算符了,3or9换成二进制就是11or1001=1011,十进制是11
'11and-1换成二进制是1011and11=1011,十进制是11,所以结果是11
Print s1, s
End Sub
'2.
Private Sub Command1_Click()
s = Not 4 * (76 - 43) ^ 2 And 5 0 '先算术运算,其次比较运算得s1
s1 = Not 4356 And False Or True '即s2
s2 = -4356 And False Or True '即s3
s3 = 0 Or True '结果为-1
Print s, s1, s2, s3
End Sub