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 / ch21code / outline.bas < prev    next >
BASIC Source File  |  1995-08-14  |  1KB  |  49 lines

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