Solved

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

Posted on 2004-03-21
7
326 Views
Last Modified: 2006-11-17
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))
    picture1(i).visible=true
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

Milind
0
Comment
Question by:asdddd
7 Comments
 
LVL 15

Expert Comment

by:unknown_routine
ID: 10644883
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
0
 
LVL 6

Expert Comment

by:___XXX_X_XXX___
ID: 10645003
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.
0
 
LVL 4

Expert Comment

by:learning_t0_pr0gram
ID: 10645231
try..

For x = 1 to 10
if x = 4 then x = x + 1
' rest of the code
Next
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 27

Expert Comment

by:Ark
ID: 10645616
For Each pic In Picture1
   Debug.print pic.Index
 ' ....
Next
0
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 100 total points
ID: 10649480
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
   
loadItBackUp:
    Select Case Err.Number
        Case 340 ' Control array element doesn't exist
            Load Picture1(i)
            Resume
           
        Case Else
            MsgBox Err.Description, , "Error " & Err.Number
    End Select
End Sub

Idle_Mind
0
 

Author Comment

by:asdddd
ID: 10669773
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.


Thanks
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 10670536
Well...you 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.

Idle_Mind
0

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

778 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question