My development environment is vb6, The problem is that after dynamically creating a Frame control with child controls, changing the Caption in the order of the Frame control's Index and specifying a Container, Index 0 takes all the Containers of the control corresponding to a different Index.
Is there a way to prevent index 0 from taking the container of a control at another index?
Here's how I tried it:
(There are 6 pieces of data in the list box.) (“All” exists at list index 0) (Index 0 of the frame and lower control already exists.)
Dim nIdx As Inteager
For nIdx = 0 to ListBox.ListCount -1
'
If nIdx <> 0 Then
'
Load Frame(nIdx)
Load TextBox(nIdx)
Frame(nIdx).Caption = ListBox.List(nIdx)
TextBox(nIdx).Container = Frame(nIdx)
Frame(nIdx).Top = Frame(nIdx - 1).Top + Frame(nIdx - 1).Height + 90
Frame(nIdx).Visible = True
TextBox(nIdx).Visible = True
End If
Next nIdx
When executed, it was expected that TextBox(Index) would be dependent on the Frame Container of the same Index, but in reality, when the Container of TextBox(Index) was changed, the Caption of Frame(0) was changed, and the TextBox(Index) in Frame(0) was all dependent.
I don't know exactly why it behaves the way it does, but the solution is simple. You need to add a Set
statement when defining the container:
Set TextBox(nIdx).Container = Frame(nIdx)
Set
is required when working with objects.