Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Unload control array?

Status
Not open for further replies.

dimsis

Programmer
Aug 6, 2000
76
GR
I use the following code to dynamically load some picture boxes into my form.

For i = 1 To .RecordCount - 1
Load Application_Screenshot(i)
next i

This event occurs when a user clicks on a listview line.
It works OK for the first time, but after another click i get a Run time error '360' Object already loaded.

How can i UNLOAD all this picture boxes only if they are already loaded?
 
dimsis,
This code is based on the great example written by Hypetia recently. I changed it (hopefully didn't break anything) and came up with this one:

Private Sub Command1_Click()
Dim objPic As Control
Dim intIndex As Integer

On Error GoTo ErrorHandle

For Each objPic In Controls
If TypeName(CallByName(Me, objPic.Name, VbGet)) = "Object" Then
If objPic.Name = "Picture1" Then
Unload objPic
End If
End If
Next

For intIndex = 1 To 3
Load Picture1(intIndex)

Picture1(intIndex).Left = Picture1(intIndex - 1).Left + Picture1(intIndex - 1).Width
Picture1(intIndex).Visible = True
Next intIndex

Exit Sub

ErrorHandle:

If Err.Number = 362 Then
Err.Clear
Resume Next
End If

End Sub

This code assumes that Picture1(0) has been created at design time while the rest of the picture controls created at run time, and all of them are the elements of the same array.

I am sure it should be improved by not relying on the error handling for error 362.

vladk
 
I get the same message (it just resumes now) because it's trying to unload the Image1(0) which has been created at design time.
I want to unload all images from 1 to image1.count and not the image1(0).
So the code must found all other indexes in tha image1 control array, and unload them everytime we click on a button.
After that it start loading again (the new one).

(i'm using this to load some images from a database. The user clicks on a line on a listview, and the correct data are reading/displaying from the database as the images too. But if the user click again in any listview line, i'm getting this object already loaded.
PS: Where is this Hypetia example you've mentioned?

Thanx for your help!
 
OK i've changed the:
If objPic.Name = "Application_Screenshot" Then
to
If objPic.Name = "Application_Screenshot" And objPic.Index <> 0 Then
and it works fine. Thanx for your help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top