主题:新手请教单选命令按钮
程序要求如下:单击"显示"命令按钮时,根据文本框中输入的内容、单选按钮和复选框状态在标签中显示出相应的信息。如:王洪男生爱好体育
我写了两种代码运行都可以:
(1)Private Sub Command1_Click()
If Check1.Value = 1 Then
b = Check1.Caption
Else
b = ""
End If
If Check2.Value = 1 Then
c = Check2.Caption
Else
c = ""
End If
If Option1.Value = True Then
a = Option1.Caption
Else
a = Option2.Caption
End If
Label2.Caption = Text1.Text + a + b + c
End Sub
(2)
Dim a, b, c As String
Private Sub Check1_Click()
If Check1.Value = 1 Then
b = Check1.Caption
Else
b = ""
End If
End Sub
Private Sub Check2_Click()
If Check2.Value = 1 Then
c = Check2.Caption
Else
c = ""
End If
End Sub
Private Sub Command1_Click()
Label2.Caption = Text1.Text + a + b + c
End Sub
Private Sub Option1_Click()
a = Option1.Caption
End Sub
Private Sub Option2_Click()
a = Option2.Caption
End Sub
我的问题:一开始运行程序时,如果用户不做任何选择就直接单击“显示”命令按钮,如果用第2种方式写的代码则标签上什么都不显示。但用第1种方法写的代码会在标签上显示“女生”,这个“女生”的值是怎么出来的呀?为什么不是“男生”呢?
[em10]
我写了两种代码运行都可以:
(1)Private Sub Command1_Click()
If Check1.Value = 1 Then
b = Check1.Caption
Else
b = ""
End If
If Check2.Value = 1 Then
c = Check2.Caption
Else
c = ""
End If
If Option1.Value = True Then
a = Option1.Caption
Else
a = Option2.Caption
End If
Label2.Caption = Text1.Text + a + b + c
End Sub
(2)
Dim a, b, c As String
Private Sub Check1_Click()
If Check1.Value = 1 Then
b = Check1.Caption
Else
b = ""
End If
End Sub
Private Sub Check2_Click()
If Check2.Value = 1 Then
c = Check2.Caption
Else
c = ""
End If
End Sub
Private Sub Command1_Click()
Label2.Caption = Text1.Text + a + b + c
End Sub
Private Sub Option1_Click()
a = Option1.Caption
End Sub
Private Sub Option2_Click()
a = Option2.Caption
End Sub
我的问题:一开始运行程序时,如果用户不做任何选择就直接单击“显示”命令按钮,如果用第2种方式写的代码则标签上什么都不显示。但用第1种方法写的代码会在标签上显示“女生”,这个“女生”的值是怎么出来的呀?为什么不是“男生”呢?
[em10]