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

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

计算command1 结束command2
出错

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

出错
无纺识别的运算符,请重新输入
确定command
展开
 我来答 举报
suoxinhuahuo
2008-10-11
知道答主
回答量:7
采纳率:0%
帮助的人:15.2万
展开全部
建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
百度网友027efc729
2008-10-09 · TA获得超过246个赞
知道小有建树答主
回答量:596
采纳率:0%
帮助的人:263万
展开全部
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
抢首赞 已赞过 已踩过<
你对这个回答的评价是?
评论 举报 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式