📄 式子计算.txt
字号:
Dim a As String
Dim i, j As Double
Dim n As Integer
Private Sub Command1_Click(Index As Integer)
If n <> 0 Then
Right a, 1
End If
If Text1.Text = "0" Then
Text1.Text = ""
End If
Select Case (Index)
Case 0
Text1.Text = Text1.Text + "0"
Case 1
Text1.Text = Text1.Text + "1"
Case 2
Text1.Text = Text1.Text + "2"
Case 3
Text1.Text = Text1.Text + "3"
Case 4
Text1.Text = Text1.Text + "4"
Case 5
Text1.Text = Text1.Text + "5"
Case 6
Text1.Text = Text1.Text + "6"
Case 7
Text1.Text = Text1.Text + "7"
Case 8
Text1.Text = Text1.Text + "8"
Case 9
Text1.Text = Text1.Text + "9"
Case 10
If Text1.Text = "" Then
Text1.Text = "0"
End If
Text1.Text = Text1.Text + "."
End Select
a = Text1.Text
End Sub
Private Sub Command2_Click(Index As Integer)
Select Case (Index)
Case 0
i = Val(a)
Text1.Text = Text1.Text + "+"
n = 1
Case 1
i = Val(a)
Text1.Text = Text1.Text + "-"
n = 2
Case 2
i = Val(a)
Text1.Text = Text1.Text + "*"
n = 3
Case 3
i = Val(a)
Text1.Text = Text1.Text + "/"
n = 4
End Select
End Sub
Private Sub Command3_Click()
j = Val(a)
Select Case (n)
Case 1
Text1.Text = i + j
a = Text1.Text
Case 2
Text1.Text = i - j
a = Text1.Text
Case 3
Text1.Text = i * j
a = Text1.Text
Case 4
Text1.Text = i / j
a = Text1.Text
End Select
End Sub
Private Sub Command4_Click()
Text1.Text = "0"
End Sub
Private Sub Command5_Click()
Text1.Text = 0
a = 0
n = 0
End Sub
Private Sub Command6_Click()
End
End Sub
Private Sub Command7_Click(Index As Integer)
Select Case (Index)
Case 0
Load 计算器
计算器.Show
Unload Me
Case 1
End Select
End Sub
Private Sub Form_Load()
End Sub
======================================================================
If n = 1 Or n = 2 Or n = 3 Or n = 4 Then
Right temp, 1
End If
If n = 6 Or n = 7 Then
Right temp, 1
End If
======================================================================
'处理优先级问题
If s1_1 > s2_2 Then
If n = 3 Then
a = a * b
ElseIf n = 4 Then
If b = 0 Then
MsgBox "错误!!除数不能为0!!请重新输入除数!!", , "错误警告"
Exit Sub
End If
a = a / b
End If
b = c
s1 = s2
ElseIf s1_1 < s2_2 Then
If n = 3 Then
b = b * c
ElseIf n = 4 Then
If b = 0 Then
MsgBox "错误!!除数不能为0!!请重新输入除数!!", , "错误警告"
Exit Sub
End If
b = b / c
End If
s2 = s3
ElseIf s1_1 = s1_2 Then
Select Case (s1)
Case "+"
a = a + b
Case "-"
a = a - b
Case "*"
a = a * b
Case "/"
If b = 0 Then
MsgBox "错误!!除数不能为0!!请重新输入除数!!", , "错误警告"
Exit Sub
End If
a = a / b
End Select
b = c
s1 = s2
s2 = s3
End If
'未编辑好待续
======================================================================
'修改中,处理符号问题
If count1 = 1 Then
s1 = Right(Text1.Text, 1)
If n = 1 Or n = 2 Then
s1_1 = 1
ElseIf n = 3 Or n = 4 Then
s1_1 = 2
End If
ElseIf count1 = 2 Then
s1 = Right(Text1.Text, 1)
If n = 1 Or n = 2 Then
s1_2 = 1
ElseIf n = 3 Or n = 4 Then
s1_2 = 2
End If
End If
If count3 = 3 Then
s3 = Right(Text1.Text, 1)
'处理优先级问题
If s1_1 > s2_2 Then
If n = 3 Then
a = a * b
ElseIf n = 4 Then
If b = 0 Then
MsgBox "错误!!除数不能为0!!请重新输入除数!!", , "错误警告"
Exit Sub
End If
a = a / b
End If
b = c
s1 = s2
ElseIf s1_1 < s2_2 Then
If n = 3 Then
b = b * c
ElseIf n = 4 Then
If b = 0 Then
MsgBox "错误!!除数不能为0!!请重新输入除数!!", , "错误警告"
Exit Sub
End If
b = b / c
End If
s2 = s3
ElseIf s1_1 = s1_2 Then
Select Case (s1)
Case "+"
a = a + b
Case "-"
a = a - b
Case "*"
a = a * b
Case "/"
If b = 0 Then
MsgBox "错误!!除数不能为0!!请重新输入除数!!", , "错误警告"
Exit Sub
End If
a = a / b
End Select
b = c
s1 = s2
s2 = s3
End If
'未编辑好待续
End If
======================================================================
c = Val(temp)
Select Case (s1)
Case "+"
a = a + b
Case "-"
a = a - b
Case "*"
a = a * b
Case "/"
If b = 0 Then
MsgBox "错误!!除数不能为0!!请重新输入除数!!", , "错误警告"
Exit Sub
End If
a = a / b
End Select
Text1.Text = a
temp = ""
======================================================================
Select Case (s1_1 - s2_2)
Case -1
Select Case (s2)
Case "*"
b = b * c
Case "/"
If b = 0 Then
MsgBox "错误!!除数不能为0!!请重新输入除数!!", , "错误警告"
Exit Sub
End If
b = b / c
End Select
s2 = s3
s2_2 = s3_3
b = c
temp2 = temp3
Case 1
Select Case (s1)
Case "+"
a = a + b
Case "-"
a = a - b
End Select
s1 = s2
s2 = s3
s1_1 = s2_2
s2_2 = s3_3
temp1 = temp2
temp2 = temp3
b = c
Case 0
Select Case (s1)
Case "+"
a = a + b
Case "-"
a = a - b
Case "*"
a = a * b
Case "/"
If b = 0 Then
MsgBox "错误!!除数不能为0!!请重新输入除数!!", , "错误警告"
Exit Sub
End If
a = a / b
End Select
b = c
s1 = s2
s2 = s3
s1_1 = s2_2
s2_2 = s3_3
End Select
======================================================================
Sub counts()
If s1_1 > s2_2 Then
If n = 3 Then
a = a * b
ElseIf n = 4 Then
If b = 0 Then
MsgBox "错误!!除数不能为0!!请重新输入除数!!", , "错误警告"
Exit Sub
End If
a = a / b
End If
b = c
s1 = s2
ElseIf s1_1 < s2_2 Then
If n = 3 Then
b = b * c
ElseIf n = 4 Then
If b = 0 Then
MsgBox "错误!!除数不能为0!!请重新输入除数!!", , "错误警告"
Exit Sub
End If
b = b / c
End If
s2 = s3
ElseIf s1_1 = s1_2 Then
Select Case (s1)
Case "+"
a = a + b
Case "-"
a = a - b
Case "*"
a = a * b
Case "/"
If b = 0 Then
MsgBox "错误!!除数不能为0!!请重新输入除数!!", , "错误警告"
Exit Sub
End If
a = a / b
End Select
b = c
s1 = s2
s2 = s3
End If
'未编辑好待续
End Sub
==============================================================================
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -