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
 
 
 
 
 
TitleAccess controls by their names as text strings
Keywordscontrol, controls, name
CategoriesControls
 
The Controls collection uses the controls' names as keys. You can use that to get a control and access its properties using its name.

Normally you wouldn't bother, you would just set the control's properties. However, you may need to find a control using a name entered by the user, calculated, or otherwise unknown at design time.

The following code displays the captions of three controls, two of which are in a control array.

 
Private Sub Form_Load()
    lblCaption(0).Caption = Controls("Label1")(0).Caption
    lblCaption(1).Caption = Controls("Label1")(1).Caption
    lblCaption(2).Caption = Controls("Command1").Caption
End Sub
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated