Home All Groups Group Topic Archive Search About

Cannot pass a control array ?

Author
22 Feb 2009 6:09 PM
Phil H
Why does it not compile ? Am I missing something ? I am sure cmdPick1 was
set up as an array in the form.   TIA


Private Sub XXX
    Call QuickPick(cmdPick1)
End Sub
----------------------------------------

Private Sub QuickPick(cmdx() As CommandButton)
'
End Sub

Author
22 Feb 2009 7:18 PM
MikeD
Show quote Hide quote
"Phil H" <phung1***@hotmail.com> wrote in message
news:%232%23w2iRlJHA.1184@TK2MSFTNGP04.phx.gbl...
> Why does it not compile ? Am I missing something ? I am sure cmdPick1 was
> set up as an array in the form.   TIA
>
>
> Private Sub XXX
>    Call QuickPick(cmdPick1)
> End Sub
> ----------------------------------------
>
> Private Sub QuickPick(cmdx() As CommandButton)
> '
> End Sub


Since both Subs are Private, they must be in the same module....so why are
you trying to pass it at all?

In any case, trying using As Object or As Variant as the parameter type.

--
Mike
Author
22 Feb 2009 9:02 PM
Phil H
The real codes are in seperate module. I just put them in the same module in
my post to make it easier to read.

I tried your suggestion to no avail. I remember someone asked this question
before. Maybe someone would know the answer.

Thanks anyway.

Show quoteHide quote
"MikeD" <nob***@nowhere.edu> wrote in message
news:O7bFNJSlJHA.2384@TK2MSFTNGP04.phx.gbl...
>
> "Phil H" <phung1***@hotmail.com> wrote in message
> news:%232%23w2iRlJHA.1184@TK2MSFTNGP04.phx.gbl...
>> Why does it not compile ? Am I missing something ? I am sure cmdPick1 was
>> set up as an array in the form.   TIA
>>
>>
>> Private Sub XXX
>>    Call QuickPick(cmdPick1)
>> End Sub
>> ----------------------------------------
>>
>> Private Sub QuickPick(cmdx() As CommandButton)
>> '
>> End Sub
>
>
> Since both Subs are Private, they must be in the same module....so why are
> you trying to pass it at all?
>
> In any case, trying using As Object or As Variant as the parameter type.
>
> --
> Mike
>
Author
22 Feb 2009 9:18 PM
David Youngblood
"Phil H" <phung1***@hotmail.com> wrote...
> I tried your suggestion to no avail. I remember someone asked this
> question before. Maybe someone would know the answer.
>
> Thanks anyway.

This works, Command2 is a control array,
Private Sub Command1_Click()
   Call QuickPick(Command2)
End Sub

Private Sub QuickPick(cmdx As Object)
    Debug.Print cmdx(0).Caption
End Sub
Author
22 Feb 2009 9:34 PM
Phil H
Yeah, that works. Syntax is slighty different from passing an array. In my
real code, i am also passing a string array and I have to pass it with ().
That's confusing.

Thanks


Show quoteHide quote
"David Youngblood" <d**@flash.net> wrote in message
news:uI3S4LTlJHA.2064@TK2MSFTNGP05.phx.gbl...
> "Phil H" <phung1***@hotmail.com> wrote...
>> I tried your suggestion to no avail. I remember someone asked this
>> question before. Maybe someone would know the answer.
>>
>> Thanks anyway.
>
> This works, Command2 is a control array,
> Private Sub Command1_Click()
>   Call QuickPick(Command2)
> End Sub
>
> Private Sub QuickPick(cmdx As Object)
>    Debug.Print cmdx(0).Caption
> End Sub
>
>
>
Author
23 Feb 2009 12:04 AM
Bill McCarthy
Hi Phil,

Control arrays are not really arrays.  They are enumerable though, so you
can use a For Each loop with them. They are more like a collection class
than an array.


Show quoteHide quote
"Phil H" <phung1***@hotmail.com> wrote in message
news:OiLRMVTlJHA.5980@TK2MSFTNGP06.phx.gbl...
> Yeah, that works. Syntax is slighty different from passing an array. In my
> real code, i am also passing a string array and I have to pass it with ().
> That's confusing.
>
> Thanks
>
>
> "David Youngblood" <d**@flash.net> wrote in message
> news:uI3S4LTlJHA.2064@TK2MSFTNGP05.phx.gbl...
>> "Phil H" <phung1***@hotmail.com> wrote...
>>> I tried your suggestion to no avail. I remember someone asked this
>>> question before. Maybe someone would know the answer.
>>>
>>> Thanks anyway.
>>
>> This works, Command2 is a control array,
>> Private Sub Command1_Click()
>>   Call QuickPick(Command2)
>> End Sub
>>
>> Private Sub QuickPick(cmdx As Object)
>>    Debug.Print cmdx(0).Caption
>> End Sub
>>
>>
>>
>
>
Author
22 Feb 2009 8:14 PM
Galen Somerville
Show quote Hide quote
"Phil H" <phung1***@hotmail.com> wrote in message
news:%232%23w2iRlJHA.1184@TK2MSFTNGP04.phx.gbl...
> Why does it not compile ? Am I missing something ? I am sure cmdPick1 was set up as an
> array in the form.   TIA
>
>
> Private Sub XXX
>    Call QuickPick(cmdPick1)
> End Sub
> ----------------------------------------
>
> Private Sub QuickPick(cmdx() As CommandButton)
> '
> End Sub
>
>

Assuming you are passing the cmdPick1 second item of the arrary, wouldn't that be:

> Private Sub XXX
>    Call QuickPick(cmdPick1(1))
> End Sub

Galen
Author
22 Feb 2009 8:58 PM
Vinchenzo vinç
Show quote Hide quote
"Phil H" <phung1***@hotmail.com> escribió en el mensaje de noticias
news:%232%23w2iRlJHA.1184@TK2MSFTNGP04.phx.gbl...
> Why does it not compile ? Am I missing something ? I am sure cmdPick1 was
> set up as an array in the form.   TIA
>
>
> Private Sub XXX
>    Call QuickPick(cmdPick1)
> End Sub
> ----------------------------------------
>
> Private Sub QuickPick(cmdx() As CommandButton)
> '
> End Sub


    Debug.Print IsArray(cmdPick1), TypeName(cmdPick1)
    Your code doesn't compile because a control array is not an array, but
an Object, so your 'Sub' should be "QuickPick(cmdx As Object)".


--
    Regards
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
( ! ) http://groups.google.com/group/microsoft.public.vb.general.discussion
( i ) http://www.microsoft.com/communities/conduct/default.mspx
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Author
22 Feb 2009 9:25 PM
Phil H
Passing as Object did not compile either.



<Vinchenzo vin? <Vinç@newsgroup.nospam>> wrote in message
Show quoteHide quote
news:eY4koBTlJHA.2460@TK2MSFTNGP06.phx.gbl...
> "Phil H" <phung1***@hotmail.com> escribi?en el mensaje de noticias
> news:%232%23w2iRlJHA.1184@TK2MSFTNGP04.phx.gbl...
>> Why does it not compile ? Am I missing something ? I am sure cmdPick1 was
>> set up as an array in the form.   TIA
>>
>>
>> Private Sub XXX
>>    Call QuickPick(cmdPick1)
>> End Sub
>> ----------------------------------------
>>
>> Private Sub QuickPick(cmdx() As CommandButton)
>> '
>> End Sub
>
>
>    Debug.Print IsArray(cmdPick1), TypeName(cmdPick1)
>    Your code doesn't compile because a control array is not an array, but
> an Object, so your 'Sub' should be "QuickPick(cmdx As Object)".
>
>
> --
>    Regards
> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
> ( ! )
> http://groups.google.com/group/microsoft.public.vb.general.discussion
> ( i ) http://www.microsoft.com/communities/conduct/default.mspx
> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
>