GenoPro Developer Home
GenoPro Home  |  SDK Home  |  Report Generator  |  Support  |  Search  |  Help  |  Site Map

Skip Navigation Links.

Collection.Add Method

The Add method is essential to grow a collection with new items. The Add method is able to add a single item, or an entire collection.

Syntax:

	collection.Add(oItem | oCollection)

For instance, if you want to have a list of all the grandchildren, you create an empty collection and add the children of each child.


Set collectionGrandChildren = Util.NewGenoCollection	' (1)
For Each c In i.children
    collectionGrandChildren.Add c.children		' (2)
Next
collectionGrandChildren.Remove i.children		' (3)
collectionGrandChildren.RemoveDuplicates ' (4) Report.WriteBr "Number of Grand Children: " & collectionGrandChildren.Count ' (5) Report.Write3Br "Grand Children: ", collectionGrandChildren.ToHtmlHyperlinks ' (6)
 

Comment (1) - New Collection
This line does create an empty collection named collectionGrandChildren. You can also start with an existing collection if convenient. For instance, you could have

Set collectionGrandChildren = i.children

while keeping in mind you have to remove those children as comment (3).

Comment (2) - Add Collection to Collection
The second phase is to loop through each child and add his/her children to the collection (if any). The result will be a list of the grandchildren.

Comment (3) - Remove from Collection
As a safety measure, the grandchildren should not include the children. There are cases where a child may be present as a child and as a grandchild, such as adoption by a grandparent or the sad story of a daughter pregnant by her father.

Comment (4) - Remove Duplicates
The same grandchild cannot be appear twice, so it is safe to remove any duplicates. Duplicate may occur in the case of an uncle adopting a child, or an error in the genealogy tree.

Comment (5) - Collection Count
The exact number of grandchildren can be calculated using the property Count.

Comment (6) - Collection Items
The method ToHtmlHyperlinks may not display the same number of grandchildren as the collection count. This is because any grandchild without a name will be skipped by the method ToHtmlHyperlinks. To resolve this problem and explicitly display each grand child, you can use the method ToHtmlHyperlinksNN.

Remarks:
The Add method does nothing if the item or the collection is empty. If you are attempting to add to the collection something else than a valid GenoPro object such as a string or a number, the Add method will throw the exception "Type Mismatch".

See Also:
Util.NewCollection
 

 

Copyright ┬ę 1998-2014. All rights reserved. GenoPro┬« and the GenoPro logo are registered trademarks.