Atlanta Custom Software Development 

 
   Search        Code/Page
 

User Login
Email

Password

 

Forgot the Password?
Services
» Web Development
» Maintenance
» Data Integration/BI
» Information Management
Programming
  Database
Automation
OS/Networking
Graphics
Links
Tools
» Regular Expr Tester
» Free Tools

GetNodeRelationship - Check if two nodes are relatives

Total Hit ( 2012)

Rate this article:     Poor     Excellent 

 Submit Your Question/Comment about this article

Rating


 


Click here to copy the following block
' Returns a value >0 if Node1 is a parent (or grandparent) of Node2
' Returns a value <0 if Node1 is a child (or grandchild) of Node2
'  in both cases the number reflects the number of levels
'  between the two nodes
' Returns 0 if the two Nodes are the same or
'  if they belong to different subtrees

Function GetNodeRelationship(ByVal Node1 As Node, _
  ByVal Node2 As Node) As Integer
  
  If Node1 Is Node2 Then
    ' this is the simplest case
    Exit Function
  ElseIf Len(Node1.FullPath) > Len(Node2.FullPath) Then
    ' if the two nodes belong to the same subtree, then
    ' Node1 is a (grand)child of Node2
    If InStr(Node1.FullPath, Node2.FullPath) = 1 Then
      ' do the loop only if the two nodes appear to
      ' belong to the same subtree
      ' check that the relationship really exists
      Do Until (Node1.Parent Is Nothing)
        Set Node1 = Node1.Parent
        GetNodeRelationship = GetNodeRelationship + 1
        If Node1 Is Node2 Then Exit Function
      Loop
    End If
  Else
    ' if the two nodes belong to the same subtree, then
    ' Node1 is a (grand)parent of Node2
    If InStr(Node2.FullPath, Node1.FullPath) = 1 Then
      ' do the loop only if the two nodes appear to
      ' belong to the same subtree
      ' check that the relationship really exists
      Do Until (Node2.Parent Is Nothing)
        Set Node2 = Node2.Parent
        GetNodeRelationship = GetNodeRelationship - 1
        If Node1 Is Node2 Then Exit Function
      Loop
    End If
  End If
  
  ' Nodes belong to different subtrees
  GetNodeRelationship = 0
  
End Function


Submitted By : Nayan Patel  (Member Since : 5/26/2004 12:23:06 PM)

Job Description : He is the moderator of this site and currently working as an independent consultant. He works with VB.net/ASP.net, SQL Server and other MS technologies. He is MCSD.net, MCDBA and MCSE. In his free time he likes to watch funny movies and doing oil painting.
View all (893) submissions by this author  (Birth Date : 7/14/1981 )


Home   |  Comment   |  Contact Us   |  Privacy Policy   |  Terms & Conditions   |  BlogsZappySys

© 2008 BinaryWorld LLC. All rights reserved.