Results 1 to 7 of 7

Thread: unloading control forms

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2000
    Posts
    13
    Is there a function that allows you to check if a control array item exists or not so that you don't need to keep track of what control array items have been loaded?

  2. #2
    Addicted Member
    Join Date
    Sep 2000
    Posts
    138
    If Control().Count<1 Then ControlNotLoaded

  3. #3
    Addicted Member Shrog's Avatar
    Join Date
    Aug 1999
    Location
    Darkest Africa
    Posts
    186

    Smile LBound and UBound

    Together with the Count function that Xmin mentioned, you can also use the LBound and UBound functions, which return the lowest array index and the highest array index respectively.

    So if you have an array of controls and you want to load another, just use UBound + 1.

    Code:
      Load lblText(lblTest.UBound + 1)
    Note that with normal arrays, you can say "UBound(MyTest)", but with control arrays you must use "MyTest.UBound".

    Hope this helps.
    Shrog

    [Edited by Shrog on 11-27-2000 at 03:23 AM]

  4. #4

    Thread Starter
    New Member
    Join Date
    Nov 2000
    Posts
    13
    Those methods are good if all of the items are being unloaded but in the program I am working on, pictureboxes etc are not unloaded according to any pattern.

    So I might have 10 picture boxes but unload 1, 4 and 9.

    Later on, I may need to add new ones or remove the rest. Do I just need to keep some way of tracking what's been loaded? eg in an array that lists the index numbers of the unloaded pages?

  5. #5
    Addicted Member Shrog's Avatar
    Join Date
    Aug 1999
    Location
    Darkest Africa
    Posts
    186
    No, there's not really a function for that. If you refer to the control that does not exist, you can trap the resulting error (see example below), but that's about all you can do. You'll probably find that keeping track of the controls yourself is the best bet.

    None the less, here is an example of a little function that checks if an instance of "txtData" exists:

    Code:
      'Check if an instance of the control exists
      Private Function ElementExists(vIndex As long) As Boolean
        Dim Dummy As String
    
        On Error GoTo ErrorHandle
        
        Dummy = txtData(vIndex).Name 
        
        ElementExists = True  
    
        Exit Function
    
      ErrorHandle:
    
        ElementExists=false
    
      End Function
    Shrog

  6. #6
    Addicted Member
    Join Date
    Sep 2000
    Posts
    138
    Or if you want to keep track of the controls you can define a Boolean array, with its elements referring to each of the controls set at load or unload time so that you know which controls have been unloaded and which loaded by testing the array.

  7. #7
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    You could always use for each statement to enumerate your controls in a controlarray
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

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