Results 1 to 5 of 5

Thread: [RESOLVED] Picture Box control Array

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2003
    Posts
    259

    Resolved [RESOLVED] Picture Box control Array

    Im currently creating an app that load a bunch of picture boxes with a control array along with label control array inside each picture box. this scrolls up the screen with assignments for employees. the problem is when a task is closed the closed picture box sticks around. what i need is a way to unload or destroy all currently load control arrays so i can reload them.

    im currently using the following.

    Code:
    Load Picture1(i)
    
    Load Label1(n)
    Set Label1(n).Container = Picture1(i)

  2. #2
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: Picture Box control Array

    Code:
    For I = Label1.Ubound to 1 Step -1
       Unload Label1(I)
    Next
    For I = Picture1.Ubound to 1 Step -1
       Unload Picture1(I)
    Next
    Edited: The order is important. You can't unload the picturebox (or any container) until its contained controls are either first unloaded or set to a different container.
    Last edited by LaVolpe; Feb 13th, 2010 at 12:01 PM.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  3. #3
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: Picture Box control Array

    In addition you cannot unload controls that were create at design time.
    For example: if Label1(0) and Label1(1) were both created at design time then if you run code below you will get error "Cannot unload controls created at design time":
    Code:
    Private Sub Command1_Click()
    Dim i As Integer
    
    '''On Error Resume Next
    
        For i = 1 To Label1.UBound
            Unload Label1(i)
        Next i
    
    End Sub
    To avoid that you'd at least need to add "On Error Resume Next" before the loop (line was commented for demonstration).

  4. #4
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: Picture Box control Array

    To make it sort-of-bulletproof you can write all of the design time ubounds into variables when form loads and use those variables when loading/unloading controls:
    Code:
    Option Explicit
    
    Private Type RunTimeLBound
        RunTimeLBound_Label As Integer
        RunTimeLBound_Picture As Integer
    End Type
    
    Dim myLBounds As RunTimeLBound
    
    Private Sub Form_Load()
    Dim i As Integer
    
        myLBounds.RunTimeLBound_Label = Label1.UBound + 1
        myLBounds.RunTimeLBound_Picture = Picture1.UBound + 1
        
        Load Picture1(myLBounds.RunTimeLBound_Picture)
        
        For i = myLBounds.RunTimeLBound_Label To 10
            Load Label1(i)
        Next i
    
    End Sub
    
    Private Sub Form_Unload()
    Dim i As Integer
    
        For i = myLBounds.RunTimeLBound_Label To Label1.UBound
            Unload Label1(i)
        Next i
        
        For i = myLBounds.RunTimeLBound_Picture To Picture1.UBound
            Unload Picture1(i)
        Next i
    
    End Sub

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2003
    Posts
    259

    Re: Picture Box control Array

    thank to both of you. I stopped this projecty about a month ago cause i could get this working right but now with your help it works great now.

    the following code is what i used:

    Code:
    For i = 1 To Label1.UBound
            Unload Label1(i)
        Next i
        i = 0
    For i = 1 To Picture1.UBound
            Unload Picture1(i)
        Next i

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width