Help about : Load picture1(index) ..........

Hello Experts ,
      i have taken a array of Picture Box (Picture1(0))

i load remaining 10 picture boxes as
for i=1 to 10
    load (picture1(i))
next i

Now if i removed control array number 4 as :-
       unload picture1(4)

and if i want to add new image to the existing 10 picture controls , when loop comes at 4 th position , it gives error

how to avoid this error message ?

is it possible to lift all remaining control array elements ?

Waiting for responce

Who is Participating?
Mike TomlinsonConnect With a Mentor Middle School Assistant TeacherCommented:
You have two basic options:

1) Don't unload controls from the array.  Set their visibility to True or False instead.

2) Use Error trapping to detect the missing control item and load it back up like this:

Private Sub Command1_Click()
    On Error GoTo loadItBackUp
    Dim i As Integer
    For i = 1 To 10
        Picture1(i).Tag = "something" ' attempt to access each item in array
    Next i
    Exit Sub
    Select Case Err.Number
        Case 340 ' Control array element doesn't exist
            Load Picture1(i)
        Case Else
            MsgBox Err.Description, , "Error " & Err.Number
    End Select
End Sub

you unload picture1(4)

so picture1(4)  does not exist and it give you an error.

lift all remaining? what exactly you mean by tha
I think, by "lift", he wants to move Picture1(5) to Picture1(4), Picture1(6) to Picture1(5).

But Picture1(4) doesn't exist after you unload it. So you must keep in mind that Picture1(4) is not usable anymore.
7 new features that'll make your work life better

It’s our mission to create a product that solves the huge challenges you face at work every day. In case you missed it, here are 7 delightful things we've added recently to monday to make it even more awesome.


For x = 1 to 10
if x = 4 then x = x + 1
' rest of the code
For Each pic In Picture1
   Debug.print pic.Index
 ' ....
asddddAuthor Commented:
Hello Idle_Mind ,
    u r code (No 1) is the suitable option for my project. It is working properly by simply making it visible=false . But can u please answer my question ?
   is there any memory problems when control array goes on increasing .
   i m going to accept u r answer.

Mike TomlinsonMiddle School Assistant TeacherCommented: can continue to load up as many pictureboxes as will fit into memory.

It would really depend on what you are doing with the pictureboxes.  Someone may have a better solution if they know your end goal.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.