【发布时间】:2023-03-26 19:22:02
【问题描述】:
我有一个用户表单,可以说三个框架,每个框架包含三个选项按钮,它们的名称连续命名含义:Frame1 = OptionButton 1, 2, 3 / Frame2 = OptionButton 4, 5, 6 / Frame3 = OptionButton 7, 8, 9
我正在尝试创建一个 for 循环来搜索每一帧检查选项按钮是否为真,如果为真,则将该特定选项按钮的标题写入公共变量。
谁能帮帮我?!
编辑:
到目前为止我的代码
For i = 1 To 7
For z = 1 To 20
If UserForm1.Controls("Frame" & i).Caption = "Amputationstyp" Then
If UserForm1.Controls("OptionButton" & z).Value = True Then
Amputationstyp = UserForm1.Controls("OptionButton" & z).Caption
End If
End If
If UserForm1.Controls("Frame" & i).Caption = "Amputationsseite" Then
If UserForm1.Controls("OptionButton" & z).Value = True Then
Amputationsseite = UserForm1.Controls("OptionButton" & z).Caption
End If
End If
If UserForm1.Controls("Frame" & i).Caption = "Restgliedstabilität" Then
If UserForm1.Controls("OptionButton" & z).Value = True Then
Restgliedstabilität = UserForm1.Controls("OptionButton" & z).Caption
End If
End If
If UserForm1.Controls("Frame" & i).Caption = "Restgliedform" Then
If UserForm1.Controls("OptionButton" & z).Value = True Then
Restgliedform = UserForm1.Controls("OptionButton" & z).Caption
End If
End If
If UserForm1.Controls("Frame" & i).Caption = "Knochenauswüchse" Then
If UserForm1.Controls("OptionButton" & z).Value = True Then
Knochenauswüchse = UserForm1.Controls("OptionButton" & z).Caption
End If
End If
If UserForm1.Controls("Frame" & i).Caption = "Hautkrankheiten (am Stumpf)" Then
If UserForm1.Controls("OptionButton" & z).Value = True Then
Hautkrankheiten = UserForm1.Controls("OptionButton" & z).Caption
End If
End If
If UserForm1.Controls("Frame" & i).Caption = "Muskeltonus" Then
If UserForm1.Controls("OptionButton" & z).Value = True Then
Muskeltonus = UserForm1.Controls("OptionButton" & z).Caption
End If
End If
Next
Next
The problem: I tried to check for the frame caption and only write something in the variable when this condition is met, but the condition is also met, when Option button three is getting checked which then leads to a wrong values in all的变量。第一个 if 语句没有按原样工作。
【问题讨论】:
-
您遇到的具体问题是什么?运行代码时会发生什么?
-
Debug.Print Me.Controls("OptionButton" & ((i - 1) * 3) + n).Value其中i是框架编号,n 是框架内的选项按钮编号 -
好吧,这和你最初的描述有点不同...
标签: vba loops for-loop userform option