First, for others trying this, ensure Frame1 size is at least w150 x h200.
Might be more sensible to rename clsScrolls > clsSpins (I originally added
scrollbars before re-reading the question).
I have two additional questions:
1) About "Dim clsScrolls(0 To 5) As New Class1" ... what if the
number 5 wasn't a constant, it may vary
You can Redim & ReDim Preserve the array just as you would any other array,
eg
Dim clsSpins() As New Class1 '
' in the inti event
Dim cntSpins as long
cntSpins = 6
Redim Preserve clsSpins(0 to 6) 'in reality never need to preserve in the
init event
for x = 0 to cntSpins
In some other routine to add a new class to the array Redim Preserve again.
However if you have an unknown or varying number might be easier to use a
Collection (particularly if you are going to delete controls during
runtime - after deleting simply Remove from the collection)
'top of the form module
Dim colSpins As New Collection
In the init routine comment or delete everything relating to the array
Dim clsSpin As Class1
'loop & code to add controls to the frame, in the loop
Set clsSpin = New Class1
Set clsSpin.spin = sbcontrol
Set clsSpin.propLab = lcontrol
clsSpin.propID = x
colSpins.Add clsSpin, CStr(x)
adding the key "x" is optional, might be usful if need to refer to specific
objects (ie class & control) in the collection elsewhere. See collection's
in help
2) I have 6 labels with 6 spinbuttons, if I need a 7 th label (also
created at runtime) displaying the sum of the 6 labels
Add a label named Label1 to Frame1, for testing add at design but change
later to add at runtime (you would need to re-define it's name after adding)
in the form module
Public Sub SpnTotal()
Dim cnt As Long
'' array method
'Dim x As Long
'For x = Lbound(clsSpins) To UBound(clsSpins)
'cnt = clsScrolls(x).spin.Value + cnt
'Next
'collection method
Dim cls As Class1
For Each cls In colSpins
cnt = cls.spin.Value + cnt
Next
Me.Frame1.Label1.Caption = cnt
End Sub
'in the spin_Change event in Class1
UserForm1.SpnTotal
Regards,
Peter T