Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Container property acting weirdly

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
I have the following code:
Code:
Private Sub Form_Load()
For x = 1 To 10
    Load Label1(x)
    With Label1(x)
        .Container = fraButtons
        .Caption = x
        .Left = 100 * x
        .Visible = True
    End With
next
end sub
Basically, it is supposed to create 10 Labels at run-time as part of a control array. Label(0) exists at design-time. Now, as I create these labels, I want to store them inside the frame called 'fraButtons', which is just a standard frame control. So, I attempt to change the Container property of each label to 'fraButtons'. However, I then get the following run-time error on the Container line:

Control "Caption Here" not found.

Where the text "Caption Here" is whatever the caption of fraButtons happens to be.

Now, I could understand if it failed because the frame didn't exist yet or something, but what on earth has the frame's caption got to do with anything? Or am I doing something very wrong?

Using VB6 on Win98.
 
Try this:
Code:
Private Sub Form_Load()
For x = 1 To 10
    Load Label1(x)
    With Label1(x)
Set
Code:
 Label1(x).Container = fraButtons
        .Caption = x
        .Left = 100 * x
        .Visible = True
    End With
Next
End Sub
 
Thanks for that. Should have seen that in the docs. Doesn't explain the (in my opinion, buggy) error message though.
 
The reason for the error is the "default" property for a frame is it's caption. Your
Code:
 .Container = fraButtons
code is trying to set the container to fraButtons.Caption instead of the fraButtons control. :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top