发表于:2008-01-03 19:57:00
楼主
Option Explicit
Private a As Single
Private b As Single
Private result As Single
Private Sub clear_click()
a = 0
b = 0
result = 0
Text1.Text = 0
Text2.Text = 0
label1.Caption = ""
label3.Caption = ""
End Sub
Private Sub exit_click()
End
End Sub
Private Sub Command1_Click()
a = CInt(Text1.Text)
b = CInt(Text2.Text)
result = a + b
label1.Caption = "+"
label3.Caption = result
End Sub
Private Sub Command2_Click()
a = CInt(Text1.Text)
b = CInt(Text2.Text)
result = a - b
label1.Caption = "-"
label3.Caption = result
End Sub
Private Sub Command3_Click()
a = CInt(Text1.Text)
b = CInt(Text2.Text)
result = a * b
label1.Caption = "*"
label3.Caption = result
End Sub
Private Sub Command4_Click()
a = CInt(Text1.Text)
b = CInt(Text2.Text)
If b = 0 Then
label3.Caption = ""
MsgBox "日啊,除数不能为0你都不知道,操!!!郁闷", vbOKOnly + vbCritical, "错误!你给我小心点"
Text2.SetFocus
Exit Sub
End If
result = a / b
label1.Caption = "/"
label3.Caption = result
End Sub
Private Sub form_load()
a = 0
b = 0
End Sub
Private Sub Text1_gotfocus()
Text1.Text = ""
End Sub
Private Sub Text1_lostfocus()
If Text1.Text = "" Then Text1.Text = "0"
End Sub
Private Sub Text2_gotfocus()
Text2.Text = ""
End Sub
Private Sub Text2_lostfocus()
If Text2.Text = "" Then Text2.Text = "0"
End Sub