Component for Sorting/Processing Recordset Hierarchies
Category:
Lists, Collections and ArraysType:
ClassesDifficulty:
AdvancedAuthor:
Raney EdenVersion Compatibility: Visual Basic 6
More information:
This project translates recordset information into useful hierarchy and node objects. It builds a mask that is very helpful when sorting hierarchies ... ie.. top level item would have a mask of '000' ... it's child would have a mask of '000 000' ... it's next child would have a mask of '000 001' and so on. This mask is useful also when you want to update all items below a given node...in this case you can update all items that have a mask that starts with their parents mask MASK LIKE = '000%' for example. You can specify the number of digits you want for each level's mask (3 was chosen here). I often use this project to just generate these mask numbers, and I store these masks with my records in the DB for sorting, updating , etc! All that is required to use the project is:
- An ADO recordset in your code that contains an identification field (ie. YourSSN for a person, etc.)
- The recordset must also contain a field that is a parent identification field (ie. ParentSSN for one of your parents, etc.)
- The recordset must also contain a field that you wish to use for a description (ie. YourName)
- The recordset must be sorted by the Parent ID field, and then by the ID field (ie. RS.Sort "ParentsSSN, YourSSN")
Dim MyHierarchy As pHierarchy.clsHierarchy
Set MyHierarchy = New pHierarchy.clsHierarchy
'RS is an ADOR.Recordset that is already loaded
RS.Sort = "ParentSSN, YourSSN"
RS.MoveFirst
MyHierarchy.Initialize "ParentSSN", "YourSSN", "YourName", "", 3
MyHierarchy.BuildStructure RS
MsgBox "First Node = " & MyHierarchy.GetFirstNode.Text
MsgBox "First Node's Mask = " & MyHierarchy.GetFirstNode.Mask
MsgBox "First Node's Child = " & MyHierarchy.GetChildNode.Text
MsgBox "First Node's Child Mask = " & _
MyHierarchy.GetChildNode.Mask
Set MyHierarchy = Nothing
Instructions: Click the link below to download the code. Select 'Save' from the IE popup dialog. Once downloaded, open the .zip file from your local drive using WinZip or a comparable program to view the contents.
Download hierarchy.zip