为了争点分,给你作一个
在窗体三添加二个textbox,一个label,4个按钮command1为控件数组,代表运算符号,一个按钮command2为计算按钮
Dim Yunsuan As String '运算序号
Private Sub Command1_Click(Index As Integer)
Yunsuan = Index '取得运算按钮序号
End Sub
Private Sub Command2_Click()
'计算
Select Case Yunsuan
Case 0
Label1.Caption = Val(Text1.Text) + Val(Text2.Text)
Case 1
Label1.Caption = Val(Text1.Text) - Val(Text2.Text)
Case 2
Label1.Caption = Val(Text1.Text) * Val(Text2.Text)
Case 3
If Val(Text2.Text) <> 0 Then
Label1.Caption = Val(Text1.Text) / Val(Text2.Text)
Else
Label1.Caption = "错误!,除数不能为0!"
End If
case clse
label1="请单击一个运算按钮!"
End Select
End Sub
在窗体上画两个文本框、一个按钮、一个标签、四个Option:
dim R as integer
Private Sub Option1_Click()
R=1
End Sub
Private Sub Option2_Click()
R=2
End Sub
Private Sub Option3_Click()
R=3
End Sub
Private Sub Option4_Click()
R=4
End Sub
Private Sub Command1_click()
dim a as single,b as single
a=val(text1.text)
b=val(text2.text)
select case R
case 1:label1.caption=a+b
case 2:label1.caption=a-b
case 1:label1.caption=a*b
case 1:label1.caption=a/b
end select
End Sub
Private Sub Option1加_Click()
Label1.Caption = Val(Text1) + Val(Text2)
End Sub
Private Sub Option2减_Click()
Label1.Caption = Text1 - Text2
End Sub
Private Sub Option3乘_Click()
Label1.Caption = Text1 * Text2
End Sub
Private Sub Option4除_Click()
Label1.Caption = Text1 / Text2
End Sub
用不着命令按钮!
如果非要用命令按钮:
Dim x&
Private Sub Command1_Click()
Label1.Caption = x
End Sub
Private Sub Option1加_Click()
x = Val(Text1) + Val(Text2)
End Sub
Private Sub Option2减_Click()
x = Text1 - Text2
End Sub
Private Sub Option3乘_Click()
x = Text1 * Text2
End Sub
Private Sub Option4除_Click()
x = Text1 / Text2
End Sub