问题 填空题

在窗体上画一个名称为Command1、标题为“计算”的命令按钮;画两个文本框,名称分别为Text1和Text2;然后画4个标签,名称分别为Label1、Label2、Label3和Label4,标题分别为“操作数1”、“操作数2”、“运算结果”和空白;再建立一个含有4个单选按钮的控件数组,名称为Optionl,标题分别为“+”、“-”、“*”和“/”。程序运行后,在Text1、Text2中输入两个数值,选中一个单选按钮后单击命令按钮,相应的计算结果显示在Label4中,程序运行情况如图所示。请在______处填入适当的内容,将程序补充完整。


Private Sub Command1_Click()
For i=0 To 3
If______=True Then
opt=Option1(i).Caption
End if
Next
Select Case ______
Case "+"
Result=Val(Text1.Text)+Val(Text2.Text)
Case "-"
Result=Val(Text1.Text)-Val(Text2.Text)
Case "*"
Result=Val(Text1.Text)*Va1(Text2.Text)
Case"/"
Result=Val(Text1.Text)/Val(Text2.Text)
End Select
______ =Result
End Sub

答案

参考答案:Option1(i).Value
opt
Label4.Caption 或 Form1.Label4. Caption 或 Me.Label4.Caption或 Command1. Parent.Label4.Caption

解析: 本题属于一个典型的小程序,使用了For和Select两个控制语句。主要思路是当单击控制按钮“计算”时,如果某一个单选按钮被选中,则把这个单选按钮的Caption值赋给变量opt。再使用Select语句,在opt表示的4种情况下,分别使Text1与Text2里面的数值做相应的计算。所以第一处应填Optionl(i).Value。根据上面的分析,第二处应填opt。第三处,根据题意,应将Result值赋给Label4的Caption属性。以上4种表达方式是等价的。

判断题
选择题