home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Programmer'…arterly (Limited Edition) / Visual_Basic_Programmers_Journal_VB-CD_Quarterly_Limited_Edition_1995.iso / code / ch22code / tstcross.bas next >
Encoding:
BASIC Source File  |  1995-08-15  |  1.3 KB  |  47 lines

  1. Attribute VB_Name = "Module1"
  2. Option Explicit
  3.  
  4. Sub Main()
  5.     #Const DebugBuild = 1
  6.     #If DebugBuild = 1 Then
  7.     Dim strLine As String, strName As String
  8.     Dim Outline As Object, Topic As Object
  9.     Set Outline = CreateObject("outline.topic")
  10.     Open "org.txt" For Input As #1
  11.     Do Until EOF(1)
  12.         Line Input #1, strLine
  13.         AddLevel strLine, Outline
  14.     Loop
  15.     Close 1
  16.     strName = InputBox("Enter your name")
  17.     Set Topic = SearchTree(strName, Outline)
  18.     MsgBox "Your boss is " & Topic.Parent.VALUE
  19.     Set Outline = Nothing
  20.     #End If
  21. End Sub
  22.  
  23. Sub AddLevel(strLine As String, objTopic As Object)
  24.     ' If the line starts with a tab...
  25.     If Mid(strLine, 1, 1) = Chr$(9) Then
  26.         ' Trim off the character and call again.
  27.         AddLevel Right(strLine, Len(strLine) - 1), _
  28.             objTopic.Topics.Item(objTopic.Topics.Count)
  29.     Else
  30.         objTopic.AddSubtopic.VALUE = strLine
  31.     End If
  32. End Sub
  33.  
  34. Function SearchTree(strName As String, objTopic As Object) As Object
  35.     Dim Item As Object
  36.     If objTopic.Topics.Count > 0 Then
  37.         For Each Item In objTopic.Topics
  38.             If Item.VALUE = strName Then
  39.                 Set SearchTree = Item
  40.             Else
  41.                 Set SearchTree = SearchTree(strName, Item)
  42.             End If
  43.         Next Item
  44.     End If
  45. End Function
  46. '
  47.