Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Recursion, how best to code ?
Message
From
24/01/2001 13:21:49
 
 
To
24/01/2001 11:33:30
Tan Aik Jin
Aranea WebLab Sdn Bhd
Kuala Lumpur, Malaysia
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00467922
Message ID:
00468047
Views:
19
Tan:

If I understand your post correctly, you want to automatically
add all linked items. For example, if the user selects C2, you
want to add items A3, C1, A1 and all items linked to A3.

If this assumption is correct, you can use a recursive function
similar to this one (untested pseudo-code):
Local lcItemID              && The ID of the item for which you
                            && want to retrieve all the linked
                            && items.
Local laLinkedItems[1]      && Store the ID of the linked items.
Local lnLinkedItemCount     && The number of items linked.

lcItemID = < some item ID >
raLinkedItems[1] = ''

lnLinkedItemCount = RetrieveLinkedItems(@laLinkedItems, lcItemID)

....

Function RetrieveLinkedItems
Lparameters raLinkedItems, tcItemsID, tlInitialized

Local lnRetVal 

If Not tlInitialized Then
   Dimension raLinkedItems[1]
   raLinkedItems[1] = ''
EndIf

lnRetVal = 0
If tcItemID is present in your table
   Locate tcItemID in your table
   
   For Each Item lcLinkedID In PointsTo
      If lcItemID is not already present in array Then
         If Empty(raLinkedItems[1]) Then
            raLinkedItems[1] = lcLinkedID
         Else
            Dimension raLinkedItems[ALEN(raLinkedItems) + 1]
            raLinkedItems[ALEN(raLinkedItems)] = lcLinkedID
         EndIf
         
         =RetrieveLinkedItems(@raLinkedItems, lcLinkedID, .T.)
      EndIf
   EndFor
EndIf

If Not tlInitialized Then
   lnRetVal = Iif(Empty(raLinkedItems[1]), 0, Alen(raLinkedItems))
Else
   *-- To denote it is a recursive call (you could return the 
   *-- number of items added as an alternative)
   lnRetVal = -1
EndIf


Return ( lnRetVal )
Daniel
Previous
Reply
Map
View

Click here to load this message in the networking platform