How to pass control array ByRef? 
Author Message
 How to pass control array ByRef?

Under VB6 SP3, is it possible to pass a Control Array byRef.

If so, how do you pass the control array in the routine call?  AND, how is the control array defined in the routine?

Thanks, Rob.



Sat, 21 Sep 2002 03:00:00 GMT  
 How to pass control array ByRef?
'add a textbox control array to a form ...

Option Explicit

Private Sub Command1_Click()

   Call passArray(Text1())

End Sub

Public Sub passArray(ctls As Variant)

   ctls(0).Text = "Hello"
   ctls(1).Text = "World"

   ctls(0).BackColor = RGB(255, 255, 0)
   ctls(1).BackColor = RGB(0, 255, 255)

  'etc etc

End Sub

--

Randy Birch, MVP Visual Basic

http://www.mvps.org/vbnet/
http://www.mvps.org/ccrp/



Under VB6 SP3, is it possible to pass a Control Array byRef.

If so, how do you pass the control array in the routine call?  AND, how is
the control array defined in the routine?

Thanks, Rob.



Sat, 21 Sep 2002 03:00:00 GMT  
 How to pass control array ByRef?
Thanks Randy,

I was hoping to retain the control name so that I could keep the "dot"
notation function when coding within the routine.

I have used  As Object before, which accomplishes the same, but I loose the
dot notation functionality while coding.

In other words, I know the type of control that will be passed in.

Private Sub cmdButton_Click(Index As Integer)

   CheckEm cmdButton

End Sub

Public Sub CheckEm(ByRef rcmdButton() As CommandButton)

   Dim lngCounter

   rcmdButton.Caption(0) = "Hello 1"
   rcmdButton.Caption(1) = "Hello 2"

   lngCounter = UBound(rcmdButton)

End Sub

Doesn't look like it is possible under VB?

Cheers, Rob.


Quote:
> 'add a textbox control array to a form ...

> Option Explicit

> Private Sub Command1_Click()

>    Call passArray(Text1())

> End Sub

> Public Sub passArray(ctls As Variant)

>    ctls(0).Text = "Hello"
>    ctls(1).Text = "World"

>    ctls(0).BackColor = RGB(255, 255, 0)
>    ctls(1).BackColor = RGB(0, 255, 255)

>   'etc etc

> End Sub

> --

> Randy Birch, MVP Visual Basic

> http://www.mvps.org/vbnet/
> http://www.mvps.org/ccrp/



> Under VB6 SP3, is it possible to pass a Control Array byRef.

> If so, how do you pass the control array in the routine call?  AND, how is
> the control array defined in the routine?

> Thanks, Rob.



Sat, 21 Sep 2002 03:00:00 GMT  
 How to pass control array ByRef?
Sure.  Following from Randy's note, and since you know the controls you
are passing (and remembering that control arrays can have 'holes' in
their sequences):

Dim lctl as commandbutton
Dim i as integer
for i=lbound(ctls) to ubound(ctls)
        set lctl=nothing
        on error resume next
        set lctl = ctls(i)
        on error goto 0
        if not lctl is nothing then
                . . .
        endif
next i

Quote:

> Thanks Randy,

> I was hoping to retain the control name so that I could keep the "dot"
> notation function when coding within the routine.

> I have used  As Object before, which accomplishes the same, but I loose the
> dot notation functionality while coding.

> In other words, I know the type of control that will be passed in.

> Private Sub cmdButton_Click(Index As Integer)

>    CheckEm cmdButton

> End Sub

> Public Sub CheckEm(ByRef rcmdButton() As CommandButton)

>    Dim lngCounter

>    rcmdButton.Caption(0) = "Hello 1"
>    rcmdButton.Caption(1) = "Hello 2"

>    lngCounter = UBound(rcmdButton)

> End Sub

> Doesn't look like it is possible under VB?

> Cheers, Rob.



> > 'add a textbox control array to a form ...

> > Option Explicit

> > Private Sub Command1_Click()

> >    Call passArray(Text1())

> > End Sub

> > Public Sub passArray(ctls As Variant)

> >    ctls(0).Text = "Hello"
> >    ctls(1).Text = "World"

> >    ctls(0).BackColor = RGB(255, 255, 0)
> >    ctls(1).BackColor = RGB(0, 255, 255)

> >   'etc etc

> > End Sub

> > --

> > Randy Birch, MVP Visual Basic

> > http://www.mvps.org/vbnet/
> > http://www.mvps.org/ccrp/



> > Under VB6 SP3, is it possible to pass a Control Array byRef.

> > If so, how do you pass the control array in the routine call?  AND, how is
> > the control array defined in the routine?

> > Thanks, Rob.



Sat, 21 Sep 2002 03:00:00 GMT  
 How to pass control array ByRef?
You might also try this.

Public Sub CheckEm(ButtonArray As Object)
   Dim ctl As CommandButton
   For Each ctl In ButtonArray
      ctl.Caption = "Hello " & ctl.Index
   Next
End Sub

David



Quote:
> Thanks Randy,

> I was hoping to retain the control name so that I could keep the "dot"
> notation function when coding within the routine.

> I have used  As Object before, which accomplishes the same, but I loose
the
> dot notation functionality while coding.

> In other words, I know the type of control that will be passed in.

> Private Sub cmdButton_Click(Index As Integer)

>    CheckEm cmdButton

> End Sub

> Public Sub CheckEm(ByRef rcmdButton() As CommandButton)

>    Dim lngCounter

>    rcmdButton.Caption(0) = "Hello 1"
>    rcmdButton.Caption(1) = "Hello 2"

>    lngCounter = UBound(rcmdButton)

> End Sub

> Doesn't look like it is possible under VB?

> Cheers, Rob.



> > 'add a textbox control array to a form ...

> > Option Explicit

> > Private Sub Command1_Click()

> >    Call passArray(Text1())

> > End Sub

> > Public Sub passArray(ctls As Variant)

> >    ctls(0).Text = "Hello"
> >    ctls(1).Text = "World"

> >    ctls(0).BackColor = RGB(255, 255, 0)
> >    ctls(1).BackColor = RGB(0, 255, 255)

> >   'etc etc

> > End Sub

> > --

> > Randy Birch, MVP Visual Basic

> > http://www.mvps.org/vbnet/
> > http://www.mvps.org/ccrp/



> > Under VB6 SP3, is it possible to pass a Control Array byRef.

> > If so, how do you pass the control array in the routine call?  AND, how
is
> > the control array defined in the routine?

> > Thanks, Rob.



Sun, 22 Sep 2002 03:00:00 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Passing a control array byRef ??

2. passing a control array byref

3. passing a byref array

4. Passing arrays byref

5. pass array to dll ByRef

6. How to pass vbscript array variable to shared object using ByRef

7. pass array to dll ByRef

8. pass array to dll ByRef

9. ByRef or not ByRef, that is the array?

10. Passing arguments ByRef to Script Control 1.0

11. passing data controls and control arrays as parameters

12. Passing By Reference myfunc(ByRef <x>)

 

 
Powered by phpBB® Forum Software