|
-
Jan 15th, 2005, 09:50 AM
#1
Thread Starter
Lively Member
Check if control is a part of an array
Is there a way to check if a control is a part of an array? I want to do this at runtime.
Last edited by john42; Jan 16th, 2005 at 01:47 PM.
Hej på dej!
-
Jan 15th, 2005, 10:01 AM
#2
Re: Check if control is a part of an array
Looping thru the controls on the form, if referencing the Index property does not generate an error, then the control is part of a control array:
VB Code:
Private Sub Command1_Click()
Dim objCtl As Control
Dim intX As Integer
On Error Resume Next
For Each objCtl In Form1.Controls
intX = objCtl.Index
If Err.Number = 0 Then
Debug.Print objCtl.Name & " is a control array."
Else
Debug.Print objCtl.Name & " is NOT a control array."
Err.Clear
End If
Next
End Sub
"It's cold gin time again ..."
Check out my website here.
-
Jan 15th, 2005, 10:20 AM
#3
Re: Check if control is a part of an array
There is a very little documented TypeName() function than does the trick:
VB Code:
If TypeName(Command1) = "Object" Then
MsgBox "Control is member of control array"
Else
MsgBox "Control is not member of control array"
End If
EDIT: for in-depth explanations visit Randy's site .
Last edited by RhinoBull; Jan 15th, 2005 at 10:25 AM.
-
Jan 15th, 2005, 03:42 PM
#4
Thread Starter
Lively Member
Re: Check if control is a part of an array
Thanks for the help guys!
RhinoBull: That was what I was looking for!
-
Jan 15th, 2005, 08:14 PM
#5
Re: Check if control is a part of an array
-
Jan 16th, 2005, 03:21 AM
#6
Re: Check if control is a part of an array
 Originally Posted by RhinoBull
There is a very little documented TypeName() function than does the trick
Brilliant!!
I'd previously used something similar to BruceG's method. It works but not very elegant. If any snippet of code deserves to be in the CodeBank, this is it!
Cheers
Pete
No trees were harmed in the making of this post, however a large number of electrons were greatly inconvenienced.
-
Jan 16th, 2005, 03:31 AM
#7
Re: Check if control is a part of an array
My way (which I've modified to fit Bruce's code) is a tiny bit simpler.
VB Code:
Private Sub Command1_Click(Index As Integer)
Dim objCtl As Control
On Error Resume Next
For Each objCtl In Form1.Controls
If objCtl.Index > -1 Then
Debug.Print objCtl.Name & " is a control array."
Else
Debug.Print objCtl.Name & " is NOT a control array."
Err.Clear
End If
Next
End Sub
BTW, John now that we've helped you, please help us and indicate that you have your answer by editing your first post in this thread and adding then green checkmark.
-
Jan 16th, 2005, 10:16 AM
#8
Re: Check if control is a part of an array
 Originally Posted by pnish
Brilliant!!
I'd previously used something similar to BruceG's method. It works but not very elegant. If any snippet of code deserves to be in the CodeBank, this is it!
Cheers
Thanks.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|