VB计算器源代码

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

Dim sum As Double
Dim flag1 As Integer
Dim flag2 As Integer
Public wen As Double
Private Sub Command19_Click()
Command24_Click
Operator = Index
NewEntry = True
End Sub
Private Sub Command1_Click(Index As Integer) Select Case Index
Case 0
wen = 0
Label1.Caption = ""
Case 1
Text1.Text = Str(wen)
Case 2
If Text1.Text = "" Then
wen = 0
Label1.Caption = ""
Else
wen = Val(Text1.Text)
Label1.Caption = "M"
End If
Text1.Text = ""
Case 3
wen = Val(Text1.Text) + wen
Label1.Caption = "M"
End Select
End Sub
Private Sub Command12_Click()
If Text1.Text <> "" Then
Text1.Text = Text1.Text * -1
Else
MsgBox "输入不能为空!", vbOKOnly, "警告"
Text1.SetFocus
End If
End Sub
Private Sub Command16_Click()
If InStr(Text1.Text, ".") = 0 Then
Text1.Text = Text1.Text & "."
Else
Exit Sub
End If
End Sub
Private Sub Command21_Click()
Text1.Text = Str(Sqr(Val(Text1.Text)))
End Sub
Private Sub Command22_Click()
sum = Text1.Text
flag1 = 5
flag2 = 1
End Sub
Private Sub Command23_Click()
Text1.Text = Str(Val(Text1.Text / 1))
flag2 = 0
End Sub
Private Sub Command24_Click()
Select Case (flag1)
Case 1
Text1.Text = sum + Text1.Text
Case 2
Text1.Text = sum - Text1.Text
Case 3
Text1.Text = sum * Text1.Text
Case 4
If Text1.Text = 0 Then
df = MsgBox("除数不能为零!请重新输入.", vbOKOnly + vbInformation, "警告") Text1.Text = ""
Text1.SetFocus
Exit Sub
Else
Text1.Text = sum / Text1.Text
End If
Case 5
If Text1.Text = 0 Then
df = MsgBox("余数不能为零!请重新输入.", vbOKOnly + vbInformation, "警告") Text1.Text = ""
Text1.SetFocus
Exit Sub
Else
Text1.Text = sum Mod Text1.Text
End If
End Select
flag2 = 0
End Sub
Private Sub Command25_Click()
If Text1.Text <> "" Then
Text1.Text = Mid(Text1.Text, 1, Len(Text1.Text) - 1)
If Text1.Text = "" Then
Text1.Text = "0"
End If
End If
End Sub
Private Sub Command26_Click()
Text1.Text = "0"
End Sub
Private Sub Command27_Click()
Text1.Text = "0"
End Sub
Private Sub Command5_Click(Index As Integer)
If flag2 = 1 Then
Text1.Text = Index
flag2 = 0
Else
If Text1.Text <> "0" Then
Text1.Text = Text1.Text & Index
Else
Text1.Text = "" & Index
End If
End If
Private Sub Command6_Click()
If Text1.Text <> "" Then
sum = Text1.Text
flag1 = 4
flag2 = 1
Else
MsgBox "输入不能为空!", vbOKOnly, "警告" Text1.SetFocus
End If
End Sub
Private Sub Command7_Click()
If Text1.Text <> "" Then
sum = Text1.Text
flag1 = 3
flag2 = 1
Else
MsgBox "输入不能为空!", vbOKOnly, "警告" Text1.SetFocus
End If
End Sub
Private Sub Command8_Click()
If Text1.Text <> "" Then
sum = Text1.Text
flag1 = 2
flag2 = 1
Else
MsgBox "输入不能为空!", vbOKOnly, "警告" Text1.SetFocus
End If
End Sub
Private Sub Command9_Click()
If Text1.Text <> "" Then
sum = Text1.Text
flag1 = 1
flag2 = 1
Else
MsgBox "输入不能为空!", vbOKOnly, "警告" Text1.SetFocus
End If。

相关文档
最新文档