VB代码帮忙指点下几个空缺~

来源:百度知道 编辑:UC知道 时间:2024/05/26 14:34:04
一个计算器,Text1,Text2是输入数字的地方,4个单选按钮分别设为+、-、×、/,Text3中显示算式和计算结果,Command1名称为“计算”。这部分代码有几处不确定怎么填,会的说下,谢了!
Private Sub Command1_Click()
Dim a As Single, b As Single, t As Single, s As Single
a = Val(Text1.Text)
b = Val(Text2.Text)
Select Case ???
Case Option1.Value
s = "+"
t = a + b
Case Option2.Value
s = "-"
t = a - b
Case Option3.Value
s = "*"
t = a * b
Case Option4.Value
s = "/"
If b <> 0 Then
t = a / b
Else
MsgBox "除数为0"
Text2.SetFocus
End If
End Select
If ??? Then Text3.Text ???
End Sub 三处空缺,第一处只填t可以吗~
不要自己新编写的,而且Text3中要显示算式

Dim a As Single, b As Single, t As Single, s As Single
Private Sub Command1_Click()
a = Val(Text1.Text)
b = Val(Text2.Text)
Select Case s
Case Option1.Value = s
t = a + b
Case Option2.Value = s
t = a - b
Case Option3.Value = s
t = a * b
Case Option4.Value = s
If b <> 0 Then
t = a / b
Else
MsgBox "除数为0"
Text2.SetFocus
End If
End Select
If Option1.Value = True Or Option2.Value = True Or Option3.Value = True Or Option4.Value = True Then Text3.Text = t
End Sub
填好了,就是一个计算器吗?

这里貌似不能用select case语句,你可以组一个控件数组,然后在申请一个模块级变量来放运算符,在单选按钮的单击事件里判断哪个被选中然后赋值对应的运算符给这个模块级变量。。最后面2个问号处,不太清楚你想写什么,所以说不准。。。