Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
MSDN Visual Basic Community
 
 
 
 
 
 
TitleSee if a control exists
Keywordscontrol, exists
CategoriesControls
 
Use On Error Resume Next. Then try to access one of the control's properties and check Err.Number to see if an error occurred.

Note that you can use UBound to find the upper bound of a control array. For example, if lblName is a control array, then lblName.LBound and lblName.UBound give the array's lower and upper bounds.

However, this does not mean every index is defined in between. Controls with indexes 0 and 5 may be loaded while no other controls are loaded.

 
Private Sub cmdTest_Click()
Dim idx As Integer
Dim lft As Single

    idx = CInt(txtIndex.Text)
    On Error Resume Next
    lft = lblControl(idx).Left
    If Err.Number <> 0 Then
        MsgBox "This control does not exist."
    Else
        MsgBox "This control is loaded."
    End If
End Sub
 
Formatted by Neil Crosby
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated