要从VB中的帧中选择选项按钮

问题描述 投票:0回答:1

我在from的每个帧中使用了4个选项按钮。就像我明智的那样,我在表单上取了10帧。.现在我只想将来自每个帧的那些optionbutton的值存储在MSaccess数据库中。因此,数据库中的结果将是每个帧的10个optionbutton的值。请帮帮我

vb6
1个回答
0
投票

假设您的问题实际上是“我如何才能在一组中获得所选的选项按钮”,那么您需要依次检查每个选项。最简单的是:

'Get the selected option from frame 1
If Frame1Option1.Value Then
  Value1 = 1
ElseIf Frame1Option2.Value Then
  Value1 = 2
ElseIf Frame1Option3.Value Then
  Value1 = 3
ElseIf Frame1Option4.Value Then
  Value1 = 4
End If

'Get the selected option from frame 2
If Frame2Option1.Value Then
  Value2 = 1
ElseIf Frame2Option2.Value Then
  Value2 = 2
ElseIf Frame2Option3.Value Then
  Value2 = 3
ElseIf Frame2Option4.Value Then
  Value2 = 4
End If

如果在每个帧中使它们成为控制数组,则可以将代码简化为:

Dim Index As Long

'Get the selected option from frame 1
For Index = Frame1Options.LBound To Frame1Options.UBound
  If Frame1Options(Index).Value Then Value1 = Index
Next

设置它们就变得很简单:

Frame1Options(Value1).Value = True
© www.soinside.com 2019 - 2024. All rights reserved.