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

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