Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

controls collection Index

Status
Not open for further replies.

enigma333

Programmer
Jul 3, 2001
42
CA
How can i determine the index of a control in the controls collection given the name.

 
Option Explicit

Private Sub Command1_Click()
MsgBox CtrlIdx("Label1")
End Sub

Private Function CtrlIdx(ByVal sName As String) As Long
Dim i As Long

CtrlIdx = -1

For i = 0 To Controls.Count - 1
If Controls(i).Name = sName Then
CtrlIdx = i
Exit For
End If
Next i
End Function
 
I was hoping to avoid looping through each one. There's no direct way for this?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top