Hi I have a userform in which there are four Frames. Each frame has couple of checkboxes. Now I want that whatever checkboxes user clicks should be displayed in message box. The following code doesn't work as it says arrays cannot be declared as public members in class.
'Class 2
Private frame_content() As String
'Module
Sub check_valid_combo(ufm As UserForm)
Dim frame_collection As New Collection
Dim frame_array As Frame
Dim num
For i = 1 To 4' no. of frames
Dim Inst As New Class2
frame_collection.Add Item:=Inst, Key:=CStr(i)
Set frame_array = ufm.Controls("Frame" & i)
For Each ctrl In frame_array.Controls
If TypeName(ctrl) = "CheckBox" Then
If ctrl.Value Then
num = num + 1
ReDim Preserve frame_content(1 To num)
Inst.frame_content(num) = ctrl.Name
End If
End If
Next ctrl
Set Inst = Nothing
num = 0
Next i
For Each MyObject In frame_collection
For i = LBound(MyObject.frame_content) To UBound(MyObject.frame_content)
MsgBox MyObject.frame_content(i)
Next i
Next MyObject
For i = 1 To frame_collection.Count ' Remove name from the collection.
frame_collection.Remove 1 ' Since collections are reindexed
' automatically, remove the first
Next
End Sub
'Class 2
Private frame_content() As String
'Module
Sub check_valid_combo(ufm As UserForm)
Dim frame_collection As New Collection
Dim frame_array As Frame
Dim num
For i = 1 To 4' no. of frames
Dim Inst As New Class2
frame_collection.Add Item:=Inst, Key:=CStr(i)
Set frame_array = ufm.Controls("Frame" & i)
For Each ctrl In frame_array.Controls
If TypeName(ctrl) = "CheckBox" Then
If ctrl.Value Then
num = num + 1
ReDim Preserve frame_content(1 To num)
Inst.frame_content(num) = ctrl.Name
End If
End If
Next ctrl
Set Inst = Nothing
num = 0
Next i
For Each MyObject In frame_collection
For i = LBound(MyObject.frame_content) To UBound(MyObject.frame_content)
MsgBox MyObject.frame_content(i)
Next i
Next MyObject
For i = 1 To frame_collection.Count ' Remove name from the collection.
frame_collection.Remove 1 ' Since collections are reindexed
' automatically, remove the first
Next
End Sub
Last edited: