Создание выпуска для-l oop - PullRequest
       67

Создание выпуска для-l oop

0 голосов
/ 04 августа 2020

У меня есть пользовательская форма, скажем, с тремя фреймами, каждый фрейм содержит три кнопки выбора, которые имеют непрерывные названия, означающие: Frame1 = OptionButton 1, 2, 3 / Frame2 = OptionButton 4, 5, 6 / Frame3 = OptionButton 7, 8, 9

Я пытаюсь создать for l oop для поиска по каждой проверке кадра, является ли кнопка выбора верной или нет, и если это правда, напишите заголовок этой конкретной c кнопки выбора в publi c переменная.

Кто-нибудь может мне помочь?!

Изменить:

Мой код на данный момент

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

Проблема: Я пытался проверить заголовок кадра и записать что-то в переменную только при выполнении этого условия, но условие также выполняется, когда проверяется кнопка выбора 3, что затем приводит к неверным значениям во всех переменных. Первый оператор if не работает как есть.

1 Ответ

0 голосов
/ 04 августа 2020

Вы можете создать функцию, которая принимает заголовок кадра и возвращает заголовок выбранной опции в этом кадре:

Private Sub Tester()

    Amputationstyp = FrameOptionFromCaption("Amputationstyp")
    Amputationsseite = FrameOptionFromCaption("Amputationsseite")
    
End Sub


'get the selected optionbutton caption from inside a frame
'  with the provided caption
Function FrameOptionFromCaption(capt As String) As String
    Dim c As Control, opt As Control
    'loop all controls in the form (inside the Form code module "Me" = the form)
    For Each c In Me.Controls
        'is this a Frame?
        If TypeName(c) = "Frame" Then
            'does the frame's caption match the one provided?
            If c.Caption = capt Then
                For Each opt In c.Controls
                    'if the frame has other types of controls you should
                    '  add a test to only look at optionbuttons...
                    If opt.Value = True Then
                        FrameOptionFromCaption = opt.Caption
                        Exit Function 'done searching
                    End If
                Next opt
            End If
        End If
    Next c
End Function
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...