编了个计算器不会用”(“和”)“优先级不会啊。怎么弄啊。。
Dim shu1 As Single, shu2 As Single, suanfu As StringPrivate Sub Command1_Click(Index As Integer)
Text1.Text = Text1.Text & Command1(Index).Caption
End Sub
Private Sub Command10_Click()
End Sub
Private Sub Command2_Click(Index As Integer)
shu1 = Val(Text1.Text) '将shu1隐藏起来
suanfu = Command2(Index).Caption
Text1.Text = ""
End Sub
Private Sub Command4_Click()
Text1.Text = Text1.Text + "."
If (InStr(Text1.Text, ".") = 1) Then '第一位不能为小数
Text1.Text = ""
End If
If InStr(Text1.Text, ".") < Len(Text1.Text) Then
'防止出现两个小数点
Text1.Text = Left(Text1.Text, Len(Text1.Text) - 1)
End If
End Sub
Private Sub Command5_Click() '开始加减乘除的运算
shu2 = Val(Text1.Text)
Select Case suanfu
Case "+"
Text1.Text = shu1 + shu2
Case "-"
Text1.Text = shu1 - shu2
Case "*"
Text1.Text = shu1 * shu2
Case "平方"
Text1.Text = shu1 * shu1
Case "立方"
Text1.Text = shu1 * shu1 * shu1
Case "^"
Text1.Text = (shu1) ^ (shu2)
Case "/"
Text1.Text = shu1 / shu2
Case "sin"
Text1.Text = Sin(shu2 * 3.14 / 180)
Case "cos"
Text1.Text = Cos(shu2 * 3.14 / 180)
Case "tan"
Text1.Text = Tan(shu2 * 3.14 / 180)
End Select
End Sub
Private Sub Command3_Click() '假如输入错误,可每次退后一格
If Text1.Text = "" Then
Exit Sub
End If
Text1.Text = Left(Text1.Text, Len(Text1.Text) - 1)
End Sub
Private Sub Command6_Click()
Text1.Text = "" '清除
End Sub
Private Sub Command7_Click()
End
End Sub
Private Sub Command8_Click()
a = Int(Rnd() * 255)
b = Int(Rnd() * 255)
c = Int(Rnd() * 255)
Form1.BackColor = RGB(a, b, c)
End Sub