Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Fill an array with a recursive function

Status
Not open for further replies.

split27

Technical User
Nov 8, 2001
15
0
0
FR
I would like to recursively fill an array.
I have a first array as a reference.
The second array has to be filled in order using the value of the first. (Sorry, maybe it's not very simple...)

For the moment I do something like that :

Dim ArrayToFill()

Function BuildArrayDependingFromValue(ArrayToSee, Value)
For Each Element in ArrayToSee
If ItShouldBeAdded(Element, Value) Then
AddToArray(Element, ArrayToFill)
> ArrayToFill = BuildArray(ArrayToSee, Element)
End If
Next
BuildArray = ArrayToFill
End Function

Sub Main()
ArrayToFill = BuildArrayDependingFromValue(ArrayToSee, MyValue)
End Sub

But this occurs an error of types on line ">".

Is someone able to help me ? Please... I hope it helps you.
--
X-) Split.
 
I can't see everything you are trying to do as you have not supplied functions ItShouldBeAdded AddtoArry and BuildArray.

Having said that you seem to have a circular reference (probably not technically a circular reference but something a bit off) - within the function why are you using the variable ArrayToFill? Why not define another array local to the function and use that within the function?

The more I look at the code the more confused I get - why do you AddtoArray, presumably changing ArrayToFill in some way, then overwrite the value of ArrayToFill with the results of BuildArray?
 
Sorry, I had no time to give further informations.

Dim OrderedArray()
Dim Length

Function OrderArray(ArrayToOrder, Value)
For Each Element in ArrayToOrder

If ElementFillAllConditions Then
Length = Length + 1
ReDim Preserve OrderedArray(Length)
OrderedArray(Length) = Element
OrderedArray = OrderArray(ArrayToOrder, Element)
End If
Next
OrderArray = OrderedArray
End Function

Sub Main(ArrayToOrder)
Length = 0
OrderedArray = OrderArray(ArrayToOrder, MyValue)
End Sub

I need to print a list of Groups (all listed in ArrayToOrder).
Each group could belong to another group in ArrayToOrder.
I want to print each root (a group without any parent) followed by its subgroups and then the next root, etc

Example :
root1
sub1
sub2
root2
sub3
sub4
So ArrayToOrder may look like : [sub1, sub4, root1, sub2, root2, sub3]
OrderedArray must look like : [root1, sub1, sub2, root2, sub3, sub4]

Wahoo ! That's all.
So could you help me ?
--
X-) Split.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top