[RESOLVED] Picture Box control Array
Im currently creating an app that load a bunch of picture boxes with a control array along with label control array inside each picture box. this scrolls up the screen with assignments for employees. the problem is when a task is closed the closed picture box sticks around. what i need is a way to unload or destroy all currently load control arrays so i can reload them.
im currently using the following.
Code:
Load Picture1(i)
Load Label1(n)
Set Label1(n).Container = Picture1(i)
Re: Picture Box control Array
Code:
For I = Label1.Ubound to 1 Step -1
Unload Label1(I)
Next
For I = Picture1.Ubound to 1 Step -1
Unload Picture1(I)
Next
Edited: The order is important. You can't unload the picturebox (or any container) until its contained controls are either first unloaded or set to a different container.
Re: Picture Box control Array
In addition you cannot unload controls that were create at design time.
For example: if Label1(0) and Label1(1) were both created at design time then if you run code below you will get error "Cannot unload controls created at design time":
Code:
Private Sub Command1_Click()
Dim i As Integer
'''On Error Resume Next
For i = 1 To Label1.UBound
Unload Label1(i)
Next i
End Sub
To avoid that you'd at least need to add "On Error Resume Next" before the loop (line was commented for demonstration).
Re: Picture Box control Array
To make it sort-of-bulletproof you can write all of the design time ubounds into variables when form loads and use those variables when loading/unloading controls:
Code:
Option Explicit
Private Type RunTimeLBound
RunTimeLBound_Label As Integer
RunTimeLBound_Picture As Integer
End Type
Dim myLBounds As RunTimeLBound
Private Sub Form_Load()
Dim i As Integer
myLBounds.RunTimeLBound_Label = Label1.UBound + 1
myLBounds.RunTimeLBound_Picture = Picture1.UBound + 1
Load Picture1(myLBounds.RunTimeLBound_Picture)
For i = myLBounds.RunTimeLBound_Label To 10
Load Label1(i)
Next i
End Sub
Private Sub Form_Unload()
Dim i As Integer
For i = myLBounds.RunTimeLBound_Label To Label1.UBound
Unload Label1(i)
Next i
For i = myLBounds.RunTimeLBound_Picture To Picture1.UBound
Unload Picture1(i)
Next i
End Sub
Re: Picture Box control Array
thank to both of you. I stopped this projecty about a month ago cause i could get this working right but now with your help it works great now.
the following code is what i used:
Code:
For i = 1 To Label1.UBound
Unload Label1(i)
Next i
i = 0
For i = 1 To Picture1.UBound
Unload Picture1(i)
Next i