Private Sub Command1_Click()
'采用控件数组时写法
For i = 0 To 3
If Option1(i).Value = True Then
MsgBox "你选择的是 " & Option1(i).Caption
End If
Next
End Sub
Private Sub Command2_Click()
'如果非控件数组且当前窗体只有一组问题答案可用
For i = 0 To Me.Controls.Count - 1
If TypeName(Me.Controls(i)) = "OptionButton" Then
If Me.Controls(i).Value = True Then
MsgBox "你选择的是 " & Me.Controls(i).Caption
End If
End If
Next
'如果有多组option 那就得在option 下写入代码
End Sub
Dim n As String
Private Sub Command1_Click()
MsgBox "你选择的是:" & n
End Sub
Private Sub Option1_Click()
n = Option1.Caption
End Sub
Private Sub Option2_Click()
n = Option2.Caption
End Sub
Private Sub Option3_Click()
n = Option3.Caption
End Sub
Private Sub Option4_Click()
n = Option4.Caption
End Sub
张志晨
建议:把Option1做成控件数组
代码会大大简化。
Dim n As String
Private Sub Command1_Click()
MsgBox "你选择的是:" & n
End Sub
Private Sub Option1_Click(Index As Integer)
n = Option1(Index).Caption
End Sub
简单吧?