Passing ParamArray to another sub ???

keldsor

Board Regular
Joined
Jun 9, 2017
Messages
52
I want to gather an unkown number of childrens ID's from one sub to another as easy as posible - something like:

Code:
Public Sub setUpFamily(IdF As Long, IdM As Long, gift As String, ParamArray id())   <<<<<<<<<< FROM HERE !!!!!!!!!!!!!!!!!!!!!
    danPar IdF, IdM, gift
    lineUpChildrenTo IdF, IdM, id() <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< USING this !!!!!!!!!!!!
End Sub


Public Sub lineUpChildrenTo(IdF As Long, IdM As Long, ParamArray id())   <<<<<<<<<<<<<<<<< TO HERE 
    ' Lines up the children to the right of the parents evenly spaced

(I have some working code here !!!!)

End Sub

The setUpFamily ( .... ) is called something like this:

setUpFamily 26,27,"31-03-1931 i Hasle Sogn", 35,32,33,28,34 <<<<<<<< sometime more Id's for the children - here only 5 !

But I can't get it to work at all !
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
When the sub setUpFamily passes the array id() to the sub lineUpChildrenTo, the array is passed as the first argument to the array id() in lineUpChildrenTo. So the array id() within lineUpChildrenTo contains a single element consisting of the original array of values. Therefore, id(0) will refer to the original array, and id(0)(0) will refer to the first element of that array, and so on.

Code:
id(0)(0) ===> first element
id(0)(1) ===> second element
etc
'
'
'

Hope this helps!
 
Upvote 0
Code:
Sub main()
  setUpFamily 10, 20, "Gold", 1, 2, 3, 4, 5
End Sub

Public Sub setUpFamily(IdF As Long, IdM As Long, gift As String, ParamArray id() As Variant)
  Dim i As Long
  
  Stop  ' and look in the Locals window
  
  Debug.Print "setUpFamily:"
  For i = 0 To UBound(id)
    Debug.Print id(i)
  Next i
  
  lineUpChildrenTo IdF, IdM, id
End Sub


Public Sub lineUpChildrenTo(IdF As Long, IdM As Long, ParamArray id() As Variant)
  Dim i             As Long
  
  Stop  ' and look in the Locals window
  
  Debug.Print "lineUpChildrenTo:"
  For i = 0 To UBound(id(0))  ' << compare vs above
    Debug.Print id(0)(i)      ' << compare vs above
  Next i
End Sub

Put Stop statements in setUpFamily and lineUpChildren as shown and look in the Locals window.

In setUpFamily, id is a 1D array, but in lineUpChildren it is a 2D array, because it was passed as a single argument.

EDIT: Clearly slow on the draw today.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,908
Messages
6,175,305
Members
452,633
Latest member
DougMo

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top