征解: 如何在大量的 Options 中,较简单的快速找出选中(Value=True)的 Option?

playyuer 2001-08-06 11:58:51
分两种情况:
1.控件数组
2.非控件数组
...全文
135 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
zeng_zhh 2001-08-06
  • 打赏
  • 举报
回复
非数组
Dim tt As OptionButton
For Each tt In Me.Controls
If tt.Value = True Then
..
Exit For
End If
Next

songyangk 2001-08-06
  • 打赏
  • 举报
回复
Options按钮又可以称做是单选钮,也就是说在一个容器内只能有一个Option的Value是True,所有如果只有一个容器那么在循环的时候找到第一个Value为True的之后就不会再有了。如果有多个容器,可以先定义这些Option是在哪些容器里,然后每一组Option里再循环找第一个Value为True的就可以了。
wbdx 2001-08-06
  • 打赏
  • 举报
回复
循环啊
假设 option1 数组
Dim ttt as vb.optionbutton
for each ttt In option1
if ttt.value = true then
msgbox "option1(" & ttt.index & ")=true"
exit for
end if
next

非数组
Dim ttt as vb.control
for each ttt in form1.controls
if typeof ttt is vb.optionbutton
if ttt.value=true then
msgbox "option1(" & ttt.index & ")=true"
exit for
end if
ned if
next


注意:没有测试
shuyi 2001-08-06
  • 打赏
  • 举报
回复
如果是控件数组就简单点用个for循环判断
如果是非控件数组那就一个一个判断咯
lanren_me 2001-08-06
  • 打赏
  • 举报
回复
非组情况只好用循环啦
lanren_me 2001-08-06
  • 打赏
  • 举报
回复
建立组:
Private Sub Option1_Click(index As Integer)
Dim a As Integer
a = index 'a即为选中的Option
MsgBox a
End Sub

weedcloud1 2001-08-06
  • 打赏
  • 举报
回复
Dim i As Variant
Dim opt As OptionButton
For Each i In Controls
If TypeOf i Is OptionButton Then
If i.Value = True Then
Set opt = i
Exit For
End If
End If
Next
opt.Caption = "OK!"
OPT就是被选成TRUE的OPTIONBUTTON的引用
leskey 2001-08-06
  • 打赏
  • 举报
回复
我也觉得没有什么好的方法,就但他们说的方法做吧:先按容器分类,然后再用for找好了

7,763

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧