使用VB6.0设计一个四则运算程序,输入两个操作数和一个操作符(+-*/),并计算出结果。
2个回答
展开全部
图片中没显示结果显示在哪,我就将结果在text3中输出,具体代码如下,有疑问,可追问:
Private Sub Form_Load()
Combo1.AddItem "+"
Combo1.AddItem "-"
Combo1.AddItem "*"
Combo1.AddItem "/"
End Sub
Private Sub Command1_Click()
If Combo1.Text = "+" Then
Text3.Text = Val(Text1.Text) + Val(Text2.Text)
ElseIf Combo1.Text = "-" Then
Text3.Text = Val(Text1.Text) - Val(Text2.Text)
ElseIf Combo1.Text = "*" Then
Text3.Text = Val(Text1.Text) * Val(Text2.Text)
ElseIf Combo1.Text = "/" Then
If Text3.Text = "0" Then
MsgBox "除数不能为0!"
Else
Text3.Text = Val(Text1.Text) / Val(Text2.Text)
End If
End If
End Sub
Private Sub Form_Load()
Combo1.AddItem "+"
Combo1.AddItem "-"
Combo1.AddItem "*"
Combo1.AddItem "/"
End Sub
Private Sub Command1_Click()
If Combo1.Text = "+" Then
Text3.Text = Val(Text1.Text) + Val(Text2.Text)
ElseIf Combo1.Text = "-" Then
Text3.Text = Val(Text1.Text) - Val(Text2.Text)
ElseIf Combo1.Text = "*" Then
Text3.Text = Val(Text1.Text) * Val(Text2.Text)
ElseIf Combo1.Text = "/" Then
If Text3.Text = "0" Then
MsgBox "除数不能为0!"
Else
Text3.Text = Val(Text1.Text) / Val(Text2.Text)
End If
End If
End Sub
展开全部
假设按钮名称是command1,文本框名称分别是text1和text2,组合框名称是combo1,代码如下:
Private Sub Command1_Click()
If Combo1.Text = "+" Then MsgBox Val(Text1) + Val(Text2)
If Combo1.Text = "-" Then MsgBox Val(Text1) - Val(Text2)
If Combo1.Text = "*" Then MsgBox Val(Text1) * Val(Text2)
If Combo1.Text = "/" Then MsgBox Val(Text1) / Val(Text2)
End Sub
Private Sub Command1_Click()
If Combo1.Text = "+" Then MsgBox Val(Text1) + Val(Text2)
If Combo1.Text = "-" Then MsgBox Val(Text1) - Val(Text2)
If Combo1.Text = "*" Then MsgBox Val(Text1) * Val(Text2)
If Combo1.Text = "/" Then MsgBox Val(Text1) / Val(Text2)
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询