Solved

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

Posted on 2004-03-21
7
328 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
LVL 28

Expert Comment

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

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 86

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

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…

734 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