4
votes

this is my code

Function GenerateInterface()
Dim ObjectsArray() As VB.Control
Dim TmpCtrl As VB.Control

ReDim ObjectsArray(1)
For Each TmpCtrl In Me.Controls
    If TmpCtrl.Container Is frConfigVars(0) Then
        Set ObjectsArray(UBound(ObjectsArray) - 1) = TmpCtrl
        ReDim Preserve ObjectsArray(UBound(ObjectsArray) + 1)
    End If
Next TmpCtrl

For i = 1 To UBound(Variables) - 1 'global array containing how many frames I need
    Load frConfigVars(i)
    frConfigVars(i).Left = 0
    frConfigVars(i).top = frConfigVars(i - 1).top + frConfigVars(i - 1).Height
    frConfigVars(i).Visible = True

     For x = 0 To UBound(ObjectsArray) - 1
         Set TmpCtrl = ObjectsArray(x)
         Load TmpCtrl(i) '<-- crashes here
         'stuff to move and view new object
     Next x
Next i 

End Function

It basically loads into a controls array the 0-indexed objects present in the frame to make me dinamycally load them how many times I need but I can't manage to load a new control from a variable itself.

I kinda got why that loading is crashing, I'm guessing the TmpCtrl contains (example) txtbox(0) and not txtbox, which I'd need to load the new object, correct? If so, how can I load the new control?

I can't create objects from scratch because there are many of them and positioning would be hell I can't call them by their name because with time I will add/remove some stuff so I don't want to touch this function again once it works

Thanks

1
See Make control array in code for a possible solution.MicSim
thanks but no, it doesn't work. In that code he addresses the object directly (lblTile), which I don't want toVash
I made a little progress (following the example in the previous explanation): TypeName(txtbox) --> Object TypeName(txtbox(0)) --> TextBox How can I iterate through the objects? This would solveVash

1 Answers

3
votes

Ok, I actually made it myself!

To access the object array itself I just need to change

Set TmpCtrl = ObjectsArray(x)

into

Set TmpCtrl = Me.Controls(ObjectsArray(x).Name)