简答题
VB
题号 #2277224
在考生文件夹中有工程文件sj4.vbp及其窗体文件sj4.frm,该程序是不完整的。
在窗体上有四个复选框,名称分别为Check1、Check2、Check3和Check4,标题分别为“足球”、“篮球”、“羽毛球”和“排球”。一个标签,名称为Label1,还有一个命令按钮,名称为Command1,标题为“选择结果”。要求程序运行后,如果选中某个复选框,当单击“选择结果”命令按钮时,则显示相应的信息。例如,如果选中“足球”和“羽毛球”复选框,单击“选择结果”命令按钮后,在标签上显示“我喜欢的运动是足球羽毛球”,如图8—4所示。

注意:请在有“?”的地方填入正确内容,然后删除“?”及代码前的所有注释符(即“”’号),但不能修改其他部分。存盘时不得改变文件名和文件夹。
参考答案
暂无
答案解析
单击命令按钮触发Click事件,本题程序中主要是判断复选按钮的状态和在标签上显示复选按钮的Caption属性值,判断复选按钮的状态可以通过Value属性来实现。如果复选按钮被选中,则Value值为1,否则Value值为0。把复选按钮的Caption属性值赋给标签的Caption属性即可显示相应的文字。补充后的代码如下:
Privat(Sub Command1 Click()
Dim str As String
str="我喜欢的运动是"
If Cheek1.Value Then
str=str+Check1.Caption
Else
str=str
End If
If Cheek2 Value Then
str=str +Check2.Caption
Else
str=str
End If
If Check3.Value Then
str=str+Check3.Caption
Else
str=Str
End If
If Check4.Value Then
str=str+Check4.Caption
Else
str=str
End If
Label1.Caption=str
End Sub
Privat(Sub Command1 Click()
Dim str As String
str="我喜欢的运动是"
If Cheek1.Value Then
str=str+Check1.Caption
Else
str=str
End If
If Cheek2 Value Then
str=str +Check2.Caption
Else
str=str
End If
If Check3.Value Then
str=str+Check3.Caption
Else
str=Str
End If
If Check4.Value Then
str=str+Check4.Caption
Else
str=str
End If
Label1.Caption=str
End Sub
Private Sub Form_Load()
Label1.Caption=""
End Sub
单击
按钮运行程序,并按要求保存。


