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?
Printable View
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?
If Control().Count<1 Then ControlNotLoaded
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.
Note that with normal arrays, you can say "UBound(MyTest)", but with control arrays you must use "MyTest.UBound".Code:Load lblText(lblTest.UBound + 1)
Hope this helps.
Shrog
[Edited by Shrog on 11-27-2000 at 03:23 AM]
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?
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:
ShrogCode:'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
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.
You could always use for each statement to enumerate your controls in a controlarray