窗体上先放置第一个option,选择这个option右击选择复制,然后粘贴,这时候会问你是否创建控件数组,选择是。如此重复几次就可以得到由几个option组成的空间数组,当然,每个option的属性你都能单独设置。 假设你的窗体上一共有3个optionPrivate Sub Command1_Click() Dim i As Integer '循环计数变量 Dim Index As Integer '被选中的option的索引号 For i = 0 To Option1.Count - 1 If Option1(i).Value = True Then Index = i Next Select Case Index Case 0 MsgBox "第一个" Case 1 MsgBox "第二个" Case 2 MsgBox "第三个" End Select End Sub
Private Sub Command1_Click() Dim a As Object For Each a In Me.Controls If TypeName(a) = "OptionButton" Then If a.Value = True Then Select Case a.Name Case "Option1" MsgBox "123" Case "Option2" MsgBox "234" Case "Option3" MsgBox "abc" End Select End If End If Next End Sub
...
else
...
end if
假设你的窗体上一共有3个optionPrivate Sub Command1_Click()
Dim i As Integer '循环计数变量
Dim Index As Integer '被选中的option的索引号
For i = 0 To Option1.Count - 1
If Option1(i).Value = True Then Index = i
Next
Select Case Index
Case 0
MsgBox "第一个"
Case 1
MsgBox "第二个"
Case 2
MsgBox "第三个"
End Select
End Sub
Dim a As Object
For Each a In Me.Controls
If TypeName(a) = "OptionButton" Then
If a.Value = True Then
Select Case a.Name
Case "Option1"
MsgBox "123"
Case "Option2"
MsgBox "234"
Case "Option3"
MsgBox "abc"
End Select
End If
End If
Next
End Sub