vb单选按钮如何做计算器

来源:百度知道 编辑:UC知道 时间:2024/06/04 01:37:44
我要一个简单的计算器 在text1.text和text2.text 2个框内输入2个数
然后有加减乘除四个单选按钮,要求选中其中一个按钮后,按command1按钮
在text3.text中显示出计算结果 我编写的代码如下,主要是不知道怎么把运算和单选按钮合在一起用
Private Sub Form_Load()
Dim a%, b%, c%
a = Val(Text1.Text)
b = Val(Text2.Text)
End Sub

Private Sub Check1_Click()
If Check1.Value = 1 Then
Text3.FontItalic = True
Else
Text3.FontItalic = False
End If
End Sub

Private Sub Check2_Click()
If Check2.Value = 1 Then
Text3.FontBold = True
Else
Text3.FontBold = False
End If
End Sub

Private Sub Command1_Click()
If Option1.Value = True Then
Text3.Text = a + b
ElseIf Option2.Value = True Then
Text3.Text = a - b
ElseIf Option3.Value = True Then
Text3.Text = a * b
ElseIf Option4.Value = True Then
Text3.Text = a / b
End If
End Sub

Private Sub Command2_Click()
Text1.Text = ""
Text2

可以就是将文本框后面增加一个数字,就是在文本框内容最后增加命令按钮所显示的数字
比如
Private Sub Command3_Click()
text1.Text = text1.Text & "3"
End Sub
或通用的按钮组
Private Sub Command1_Click(Index As Integer)
text1.Text = text1.Text & Index
End Sub
都行

控件有1个按钮 2个label 2个text 4个option数组控件 代码如下

Private Sub Command1_Click()
Label2.Caption = "等于:"
If Option1(0).Value = True Then Label2.Caption = Label2.Caption & (Val(Text1.Text) + Val(Text2.Text))
If Option1(1).Value = True Then Label2.Caption = Label2.Caption & (Val(Text1.Text) - Val(Text2.Text))
If Option1(2).Value = True Then Label2.Caption = Label2.Caption & (Val(Text1.Text) * Val(Text2.Text))
If Option1(3).Value = True Then Label2.Caption = Label2.Caption & (Val(Text1.Text) / Val(Text2.Text))
End Sub

Private Sub Option1_Click(Index As Integer)
Select Case Index
Case 0
Label1.Caption = "+"
Case 1
Label1.Caption