一道vb题求解,高手进来帮帮忙啊

请大家帮帮忙
4.简单计算器的实现。要求:使用select case语句和if语句,能进行+、-、*、/、\和mod六种运算,有基本的数据合法性和运算合法性检验报错能力如图: 简易计算器
输入数1 运算符 输入数2 计算结果

计算command1 结束command2
出错

分母为零,请重新输入
确定command

出错
无纺识别的运算符,请重新输入
确定command

建text1 为输入的第1个数,一个combobox存放运算符号,text2 为输入的第二个数 text3 为得数 按钮1为确定 按钮2为退出
=========

Private Sub Command1_Click()
If IsNumeric(Text1.Text) And Text1.Text <> "" And IsNumeric(Text3.Text) And Text3.Text <> "" Then
Select Case Combo1.ListIndex
Case 0
Text3.Text = Val(Text1.Text) + Val(Text2.Text)
Case 1
Text3.Text = Val(Text1.Text) - Val(Text2.Text)
Case 2
Text3.Text = Val(Text1.Text) * Val(Text2.Text)
Case 3
If Val(Text1.Text) <> 0 Then
Text3.Text = Val(Text1.Text) / Val(Text2.Text)
Else
MsgBox "分母不能为0", , "错误"
End If
Case 4
Text3.Text = Val(Text1.Text) \ Val(Text2.Text)
Case 5
Text3.Text = Val(Text1.Text) Mod Val(Text2.Text)
End Select
Else
MsgBox "请输入操作数", , "错误"

End If

End Sub

Private Sub Command2_Click()
End

End Sub

Private Sub Form_Load()

Combo1.AddItem "+"
Combo1.AddItem "-"
Combo1.AddItem "*"
Combo1.AddItem "/"
Combo1.AddItem "\"
Combo1.AddItem "mod"

End Sub
温馨提示:内容为网友见解,仅供参考
第1个回答  2008-10-09
Private Sub Command1_Click(Index As Integer)
Text1.SetFocus

Select Case Index
Case 0
If Text1.Text = "0." Then Text1.Text = ""
Text1.Text = Text1.Text & 1
Case 1
If Text1.Text = "0." Then Text1.Text = ""
Text1.Text = Text1.Text & 2
Case 2
If Text1.Text = "0." Then Text1.Text = ""
Text1.Text = Text1.Text & 3
Case 3
If Text1.Text = "0." Then Text1.Text = ""
Text1.Text = Text1.Text & 4
Case 4
If Text1.Text = "0." Then Text1.Text = ""
Text1.Text = Text1.Text & 5
Case 5
If Text1.Text = "0." Then Text1.Text = ""
Text1.Text = Text1.Text & 6
Case 6
If Text1.Text = "0." Then Text1.Text = ""
Text1.Text = Text1.Text & 7
Case 7
If Text1.Text = "0." Then Text1.Text = ""
Text1.Text = Text1.Text & 8
Case 8
If Text1.Text = "0." Then Text1.Text = ""
Text1.Text = Text1.Text & 9
Case 9
Text1.Text = Text1.Text & "0"
Case 10
If Text1.Text = "0." Then Text1.Text = ""
If Text1.Text = "" Then Exit Sub
If zhengfu = True Then Text1.Text = "-" & Text1.Text: zhengfu = False

Case 11
If zpoint = True Then Text1.Text = Text1.Text & ".": zpoint = False
Case 12
first(1) = Text1.Text: zpoint = True: zhengfu = True
fuhao(1) = "+"
Text1.Text = ""
Case 13
first(1) = Text1.Text: zpoint = True: zhengfu = True
fuhao(1) = "-"
Text1.Text = ""
Case 14: zpoint = True: zhengfu = True
first(1) = Text1.Text
fuhao(1) = "*"
Text1.Text = ""
Case 15
first(1) = Text1.Text: zpoint = True: zhengfu = True
fuhao(1) = "/"
Text1.Text = ""
Case 16
Text1.Text = "": zhengfu = True: zpoint = True
Case 17
Text1.Text = "": zhengfu = True: fuhao(1) = "": first(1) = "": zpoint = True
first(1) = 0
Case 18
If fuhao(1) = "+" Then Text1.Text = Val(Text1.Text) + Val(first(1))
If fuhao(1) = "-" Then Text1.Text = Val(first(1)) - Val(Text1.Text)
If fuhao(1) = "*" Then Text1.Text = Val(Text1.Text) * Val(first(1))
If fuhao(1) = "/" Then Text1.Text = Val(first(1)) / Val(Text1.Text)

End Select
End Sub

Private Sub Form_Load()
zhengfu = True
zpoint = True
End Sub

Private Sub hanshu_Click()
Form3.Show
End Sub

Private Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer)
If Text1.Text = "0." Then Text1.Text = ""
End Sub

Private Sub Text1_KeyPress(KeyAscii As Integer)
If Text1.Text = "0." And KeyAscii = 46 Then Exit Sub
If Text1.Text = "0." Then Text1.Text = ""
If zpoint = True And KeyAscii = 46 Then
zpoint = False
ElseIf zpoint = False And KeyAscii = 46 Then KeyAscii = 0
End If
End Sub
相似回答