I have MANUALLY made a family tree i Excel like this:
Never mind you can't see the details - you can see a sort of columns representing generations.
The problem is to find of how many generations I need to have and which generation each person
should belong to.
The structure behind the tree is this table:
Where BarnID is an ID for a person and F1, F2 ... is id's for the parents of that person.
Sometimes a person has 1, 2 or 3 or more parents.
If a person has no parents he is NOT listed in the table at all.
I have this recursive code to traverse the tree from right to left starting with an Id.
Code:
Function findG(tb As DAO.Recordset, Id As Long) As Integer
' Using RECURSIVE call in this function
' If Id is not found -1 is returned
Dim F As Long, n As Integer
Dim G As Integer
Dim bm As Variant
G = -1
With tb
.Index = "PrimaryKey"
.Seek "=", Id
If .NoMatch = False Then
bm = .Bookmark
F = 1
Do
Id = .Fields("F" & F) ' now take THIS parentId
n = findG(tb, Id)
G = G + 1
If n > G Then G = n
F = F + 1
.Bookmark = bm
Loop Until .Fields("F" & F) = 0
End If
findG = G
End With
End Function
The code is working fine BUT it's returning WRONG generation numbers !
Take the person in the upper right corner - the code runs through all the supposed
branches it should - including the long one which is defining the generation
number - the upper right person should have the generation number 7.
The code is returning 5 because it runs through a "shorter" branch as the
last run !
I know there is much more to do for EACH person to have the rcorrect generation
number but in the first place I need to find the "longest path".
How can I change the code so it can remember the LONGEST PATH through
the anchesters ?