在运算数1和运算数2所对应的文本框输入运算数,然后选择运算符的单选按钮,最后单击=,在运算结果所对应的文本输出运算结果.
我已经在窗体弄好了那些控件.可是我不知道那个cammond1=,就是怎样按=才显示出结果.请帮助下我这个初学者,下面我写的程序,有错了.请问怎样改才行??不要笑偶哦..
Private Sub Option1_Click()
A = Val(Text1.Text)
B = Val(Text2.Text)
C = A + B
End Sub
Private Sub Option2_Click()
A = Val(Text1.Text)
B = Val(Text2.Text)
C = A - B
End Sub
Private Sub Option3_Click()
A = Val(Text1.Text)
B = Val(Text2.Text)
C = A * B
End Sub
Private Sub Option4_Click()
A = Val(Text1.Text)
B = Val(Text2.Text)
If B <> 0 Then
C = A / B
Else
C = "输入操作数错误"
End If
End Sub
Private Sub Command1_Click()
Text6.Text = C
End Sub
按=,可是结果那个文本框没有数据出来.
谢谢了.
參考答案:'添加3个TEXT,1个Command(=),4个OPTION(+-*/)
Private Sub Command1_Click()
a = Val(Text1)
b = Val(Text2)
If Option1.Value = True Then
Text3 = a + b
ElseIf Option2.Value = True Then
Text3 = a - b
ElseIf Option3.Value = True Then
Text3 = a * b
End If
If Option4.Value = True And b <> 0 Then
Text3 = a / b
ElseIf Option4.Value = True And b = 0 Then
MsgBox "出错"
End If
End Sub