I would like to Get the value of a Boolean variable by passing its name as text.
The following line works for me in another file
Is there an equivalent as the above or something else to get value of variables using the names of the variables as strings?
This is my code:
Any suggestions appreciated.
Also, please let me know why the MsgBox is in lower in my code.
Sorry, for the trouble. Thanks in advance.
The following line works for me in another file
Code:
lablnam = Me.Controls(StrArrOptBtnLblNam(ctra, 1)).Caption
This is my code:
Code:
Private Sub UserForm_Click()
'get the value of a boolean variable by passing its name as text
Dim Address(4) As String
Dim ChosenName As Boolean
Dim ChosenAddress As Boolean
Dim ChosenState As Boolean
Dim ChosenPinCode As Boolean
Dim ChosenFieldList As String
Dim i As Integer
Dim SelFldNam() As String
Address(0) = "ChosenName"
Address(1) = "ChosenAddress"
Address(2) = "ChosenState"
Address(3) = "ChosenPinCode"
'Now, the User choses the option button for the ChosenName in the Userform.
'So, the result is...
ChosenName = True
ChosenFieldList = "ChosenName, ChosenAddress, ChosenState, ChosenPinCode"
SelFldNam = Split(ChosenFieldList, ",") 'Text Array populated
For i = LBound(SelFldNam) To UBound(SelFldNam)
msgbox "SelFldNam=" & i & ". " & SelFldNam(i)
'Address(0) = "ChosenName"
'SelFldNam(i) = "ChosenName"
If SelFldNam(i) = True Then 'checking whether ChosenName is true
msgbox "Address(" & i & ")=" & SelFldNam(i) & "= true"
'some actions as this is true
'Please note:
'The following line works for me in another file
'lablnam = Me.Controls(StrArrOptBtnLblNam(ctra, 1)).Caption
'Is there an equivalent as the above to call variables using strings?
Else
msgbox "Address(" & i & ")=" & SelFldNam(i) & "= false"
'no actions as this is false
End If
Next i
End Sub
Also, please let me know why the MsgBox is in lower in my code.
Sorry, for the trouble. Thanks in advance.
Last edited: