Private Function FindTVString(nodeParent As Node, _
sTarget As String, _ Compare As VbCompareMethod) As Integer Dim nodeChild As Node Dim wIdx As Integer ' First check the parent node's text ' If found, return it's index and exit. If InStr(1, nodeParent.Text, sTarget, Compare) Then FindTVString = nodeParent.Index Exit Function End If ' Get the parent node's first child Set nodeChild = nodeParent.Child ' Now walk through the current parent node's children Do While Not (nodeChild Is Nothing) ' If the current child node has it's own children... If nodeChild.Children Then ' Recursively call this proc searching for the target string. ' If found, return the index and exit. wIdx = FindTVString(nodeChild, sTarget, Compare) If wIdx Then FindTVString = wIdx Exit Function End If Else ' Check the current child node's text (it has no children) ' If found, return it's index and exit. If InStr(1, nodeChild.Text, sTarget, Compare) Then FindTVString = nodeChild.Index Exit Function End If End If ' Get the current child node's next sibling Set nodeChild = nodeChild.Next Loop End Function |