7,762
社区成员
发帖
与我相关
我的任务
分享
Dim YS1 As Single, YS2 As Single, YSJG As Single, YSF As String, HDS As Single
Private Sub Command1_Click(Index As Integer)
If HDS <> 0 Then YSF = "": YS1 = 0: YS2 = 0: HDS = 0: Text1.Text = ""
If YS1 <> 0 And YSF <> "" And YS2 <> 0 Then YS1 = 0: YSH = "": YS2 = 0: Text1.Text = ""
Select Case Index
Case 0: Text1.Text = Text1.Text & Command1(0).Caption
Case 1: Text1.Text = Text1.Text & Command1(1).Caption
Case 2: Text1.Text = Text1.Text & Command1(2).Caption
Case 3: Text1.Text = Text1.Text & Command1(3).Caption
Case 4: Text1.Text = Text1.Text & Command1(4).Caption
Case 5: Text1.Text = Text1.Text & Command1(5).Caption
Case 6: Text1.Text = Text1.Text & Command1(6).Caption
Case 7: Text1.Text = Text1.Text & Command1(7).Caption
Case 8: Text1.Text = Text1.Text & Command1(8).Caption
Case 9: Text1.Text = Text1.Text & Command1(9).Caption
Case 10:
If Left(Text1.Text, 1) = "-" Then
Text1.Text = Right(Text1.Text, Len(Text1.Text) - 1)
Else
Text1.Text = "-" & Text1.Text
End If
Case 11: Text1.Text = Text1.Text & Command1(11).Caption
End Select
End Sub
Private Sub Command2_Click(Index As Integer)
If Index = 0 Then '+
YSF = "+"
YS1 = Val(Text1.Text)
Text1.Text = ""
ElseIf Index = 1 Then '-
YSF = "-"
YS1 = Val(Text1.Text)
Text1.Text = ""
ElseIf Index = 2 Then '*
YSF = "*"
YS1 = Val(Text1.Text)
Text1.Text = ""
ElseIf Index = 3 Then '/
YSF = "/"
YS1 = Val(Text1.Text)
Text1.Text = ""
ElseIf Index = 4 Then '=
YS2 = Val(Text1.Text)
If YS2 = 0 Then
MsgBox "你没有输入第二个运算数,请输入", 16, "错误提示!"
Exit Sub
End If
Select Case YSF
Case "+": Text1.Text = YS1 + YS2
Case "-": Text1.Text = YS1 - YS2
Case "*": Text1.Text = YS1 * YS2
Case "/": Text1.Text = YS1 / YS2
End Select
'YSF = "": YS1 = 0: YS2 = 0
End If
End Sub
Private Sub Command6_Click()
'AC
Text1.Text = ""
YSF = "": YS1 = 0: YS2 = 0
End Sub
Private Sub Form_Load()
Text1.Text = ""
YSF = "": YS1 = 0: YS2 = 0
End Sub
Private Sub 按钮0_Click()
If Val(Text1) = 1 Then
If Val(Label1) <> 0 Then
Label1.Caption = Val(Label1) & 0
End If
End If
If Val(Text1) = 2 Then
If Val(Label3) <> 0 Then
Label3.Caption = Val(Label3) & 0
End If
End If
End Sub
Private Sub 按钮1_Click()
If Val(Text1) = 1 Then
If Val(Label1) <> 0 Then
Label1.Caption = Val(Label1) & 1
End If
If Val(Label1) = 0 Then
Label1.Caption = 1
End If
End If
If Val(Text1) = 2 Then
If Val(Label3) <> 0 Then
Label3.Caption = Val(Label3) & 1
End If
If Val(Label3) = 0 Then
Label3.Caption = 1
End If
End If
End Sub
Private Sub 按钮2_Click()
If Val(Text1) = 1 Then
If Val(Label1) <> 0 Then
Label1.Caption = Val(Label1) & 2
End If
If Val(Label1) = 0 Then
Label1.Caption = 2
End If
End If
If Val(Text1) = 2 Then
If Val(Label3) <> 0 Then
Label3.Caption = Val(Label3) & 2
End If
If Val(Label3) = 0 Then
Label3.Caption = 2
End If
End If
End Sub
Private Sub 按钮3_Click()
If Val(Text1) = 1 Then
If Val(Label1) <> 0 Then
Label1.Caption = Val(Label1) & 3
End If
If Val(Label1) = 0 Then
Label1.Caption = 3
End If
End If
If Val(Text1) = 2 Then
If Val(Label3) <> 0 Then
Label3.Caption = Val(Label3) & 3
End If
If Val(Label3) = 0 Then
Label3.Caption = 3
End If
End If
End Sub
Private Sub 按钮4_Click()
If Val(Text1) = 1 Then
If Val(Label1) <> 0 Then
Label1.Caption = Val(Label1) & 4
End If
If Val(Label1) = 0 Then
Label1.Caption = 4
End If
End If
If Val(Text1) = 2 Then
If Val(Label3) <> 0 Then
Label3.Caption = Val(Label3) & 4
End If
If Val(Label3) = 0 Then
Label3.Caption = 4
End If
End If
End Sub
Private Sub 按钮5_Click(Index As Integer)
If Val(Text1) = 1 Then
If Val(Label1) <> 0 Then
Label1.Caption = Val(Label1) & 5
End If
If Val(Label1) = 0 Then
Label1.Caption = 5
End If
End If
If Val(Text1) = 2 Then
If Val(Label3) <> 0 Then
Label3.Caption = Val(Label3) & 5
End If
If Val(Label3) = 0 Then
Label3.Caption = 5
End If
End If
End Sub
Private Sub 按钮6_Click(Index As Integer)
If Val(Text1) = 1 Then
If Val(Label1) <> 0 Then
Label1.Caption = Val(Label1) & 6
End If
If Val(Label1) = 0 Then
Label1.Caption = 6
End If
End If
If Val(Text1) = 2 Then
If Val(Label3) <> 0 Then
Label3.Caption = Val(Label3) & 6
End If
If Val(Label3) = 0 Then
Label3.Caption = 6
End If
End If
End Sub
Private Sub 按钮7_Click()
If Val(Text1) = 1 Then
If Val(Label1) <> 0 Then
Label1.Caption = Val(Label1) & 7
End If
If Val(Label1) = 0 Then
Label1.Caption = 7
End If
End If
If Val(Text1) = 2 Then
If Val(Label3) <> 0 Then
Label3.Caption = Val(Label3) & 7
End If
If Val(Label3) = 0 Then
Label3.Caption = 7
End If
End If
End Sub
Private Sub 按钮8_Click()
If Val(Text1) = 1 Then
If Val(Label1) <> 0 Then
Label1.Caption = Val(Label1) & 8
End If
If Val(Label1) = 0 Then
Label1.Caption = 8
End If
End If
If Val(Text1) = 2 Then
If Val(Label3) <> 0 Then
Label3.Caption = Val(Label3) & 8
End If
If Val(Label3) = 0 Then
Label3.Caption = 8
End If
End If
End Sub
Private Sub 按钮9_Click(Index As Integer)
If Val(Text1) = 1 Then
If Val(Label1) <> 0 Then
Label1.Caption = Val(Label1) & 9
End If
If Val(Label1) = 0 Then
Label1.Caption = 9
End If
End If
If Val(Text1) = 2 Then
If Val(Label3) <> 0 Then
Label3.Caption = Val(Label3) & 9
End If
If Val(Label3) = 0 Then
Label3.Caption = 9
End If
End If
End Sub
Private Sub 乘_Click()
Label2.Caption = "×"
Label8.Caption = 3
End Sub
Private Sub 除_Click()
Label2.Caption = "÷"
Label8.Caption = 4
End Sub
Private Sub 等于_Click()
If Val(Label8.Caption) = 1 Then Label5.Caption = Val(Label1) + Val(Label3)
If Val(Label8.Caption) = 2 Then Label5.Caption = Val(Label1) - Val(Label3)
If Val(Label8.Caption) = 3 Then Label5.Caption = Val(Label1) * Val(Label3)
If Val(Label8.Caption) = 4 Then
If Val(Label3) = 0 Then
MsgBox "除数不可以为零"
End If
If Val(Label3) <> 0 Then Label5.Caption = Val(Label1) / Val(Label3)
a = Len(Label5.Caption) - 1
If Left(Label5.Caption, 1) = "." Then
Label5.Caption = 0 & Left(Label5.Caption, 1) & Right(Label5.Caption, a)
End If
End If
End Sub
Private Sub 加_Click()
Label2.Caption = "+"
Label8.Caption = 1
End Sub
Private Sub 减_Click()
Label2.Caption = "-"
Label8.Caption = 2
End Sub
Private Sub 删除_Click()
If Val(Text1) = 1 Then
If Len(Label1.Caption) = 1 Then
Label1.Caption = 0
Else
Label9.Caption = Len(Label1.Caption) - 1
Label1.Caption = Left(Label1.Caption, Label9.Caption)
End If
End If
If Val(Text1) = 2 Then
If Len(Label3.Caption) = 1 Then
Label3.Caption = 0
Else
Label9.Caption = Len(Label3.Caption) - 1
Label3.Caption = Left(Label3.Caption, Label9.Caption)
End If
End If
End Sub