Solved

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

Posted on 2004-03-21
7
327 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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 28

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

830 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