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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Control Array Members 2

Status
Not open for further replies.

StewartJ

Programmer
Apr 3, 2002
74
GB
My function has been passed a control as a parameter. Please could you explain how I determine whether it is a member of a control array?
 
I am pretty sure this will work for what you want. There may be a better way but I don't know about it.... give this a try:

Code:
Private Sub IsMyTextboxAnArray(MyTextbox As Object)
    On Error Resume Next
    Dim Count As Long
    
    Count = MyTextbox.Count
    If Err.Number = 438 Then
        Debug.Print "Not a Control Array"
    Else
        Debug.Print "Control array with " & Count & " elements"
    End If
End Sub
 
bjd4jc

If a "control" is being passed then control.count will always fail.
Use Index. It will fail if control is not a member of a control array.
Private Function IsInControlArray(MyCtl As Control) as boolean
Dim lngIndex As Long
On Error Resume Next
lngIndex = MyCtl.Index
if Err.Number <> 0 then lngIndex = -1
On error goto 0
IsInControlArray = (lngIndex >= 0)
End Sub


Generate Forms/Controls Resizing/Tabbing Class
Compare Code (Text)
Generate Sort Class in VB or VBScript
 
Thanks, guys. I prefer not to use the error functionality like this (just because its inelegant!) but I guess it's the only way here.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top