Hi Rick ...
I thought I responded to that email. I agree, but also find the function
handy as it reliably determines the control type when a control of unknown
type passed to a method as object. As I could foresee use for this I
maintained the page ...
Private Sub Command1_Click( )
Call something(Comma nd1)
Call something(Comma nd2)
End Sub
Private Sub something(obj As Object)
If IsControlInArra y(obj) Then
obj(0).Caption = "an array control"
Else
obj.Caption = "non-array control"
End If
End Sub
Private Function IsControlInArra y(ctl As Object) As Boolean
IsControlInArra y = TypeName(ctl) = "Object"
End Function
Were you to use the same test with:
Private Sub Command2_Click( Index As Integer)
Call something(Me.Ac tiveControl)
End Sub
.... the result is "non-array control", as the control resolves to
CommandButton since effectively "Command(0) ' or "Command2(1 )" was passed.
--
Randy Birch
MS MVP Visual Basic
http://vbnet.mvps.org/
"Rick Rothstein" <ri************ @NOSPAMcomcast. net> wrote in message
news:ro******** ************@co mcast.com...
:>
http://vbnet.mvps.org/code/helpers/iscontrolinarray.htm - a one-line
: > function that returns True if the passed control is a member of a
: control
: > array, or False if it is not, and without requiring error trapping.
:
: The following is from an email I sent you about 3 years ago. I'm
: guessing we both lost track of it because it was never included in the
: web page's text. (Either that, or you just don't like what I wrote.<g>)
: Anyway, I'm posting it here because I think it adds something useful to
: the discussion.
:
: In the routine you cited in the above link, you offer four examples of
: calling the IsControlInArra y function listed in the routine. I think
: they all miss the true usefulness of the code since you are calling the
: IsControlInArra y function using "hard coded" control objects. If you
: know enough to pass Option2 instead of Option2(0) into the function, you
: probably already know whether you have a control array or not (so you
: don't need the function to tell you). I envisioned this codes usefulness
: to be when used either with the ActiveControl property of a Form
: (whether the ActiveForm or not) or when used in a Function/Sub where it
: would use the control passed into the Function/Sub as its direct
: argument. It is in these types of situations where the nature of the
: control would not be known beforehand and asking IsControlInArra y would
: truly be useful.
:
: Rick - MVP
: