home *** CD-ROM | disk | FTP | other *** search
/ Planet Source Code Jumbo …e CD Visual Basic 1 to 7 / 1_2002.ISO / Data / Zips / CODE_UPLOAD1068810162000.psc / Modules / modMain.bas < prev   
Encoding:
BASIC Source File  |  2000-10-16  |  5.3 KB  |  140 lines

  1. Attribute VB_Name = "modMain"
  2. ' ***********************************************
  3. ' * INI Viewer Engine Alpha                     *
  4. ' * Code by: Michael Heath                      *
  5. ' * Code Date: 15 Oct 2000                      *
  6. ' * Email:  mheath@indy.net                     *
  7. ' * -----------------------                     *
  8. ' *                                             *
  9. ' *                                             *
  10. ' * This code was designed to view ini files in *
  11. ' * A tree node enviroment.                     *
  12. ' *                                             *
  13. ' * The purpose of this code was to provide an  *
  14. ' * Easy example of using Tree Nodes in VB6.    *
  15. ' *                                             *
  16. ' * I believe that almost any new VBer will find*
  17. ' * This code useful and easy to use.           *
  18. ' *                                             *
  19. ' * The next revision of this code will enable  *
  20. ' * Users to not only view ini files but edit   *
  21. ' * Them from the GUI.                          *
  22. ' *                                             *
  23. ' * Please enjoy the code and send me your      *
  24. ' * Comments or suggestions at mheath@indy.net  *
  25. ' ***********************************************
  26.  
  27. ' Notes:
  28. '
  29. ' You will notice on frmMain there is an object called imgSmall
  30. ' This image list must be initiated with the tree node before
  31. ' It will work.  To do that, you would right click on the tree node
  32. ' And select properties.  On the image list combo box under the General
  33. ' Tab, choose the Image list available.
  34. ' In this example, you shouldn't have to do that.  This is a reference
  35. ' If you decide to use a tree node in the future.
  36.  
  37. ' To keep my node structure in order, you will notice that I
  38. ' Declared 5 different nodes.  You will also notice that
  39. ' I set the node.tag of each according to what type of node it
  40. ' Is.  This will come in handy later on for identifying what
  41. ' Type of node is being selected.
  42.  
  43.  
  44. Public nodRoot As Node ' Root Node - INI File Name
  45. Public nodSec As Node ' Sections in INI File
  46. Public nodKey As Node ' Key of INI File
  47. Public nodValue As Node ' Value of Key
  48. Public nodCurrentProj As Node
  49.  
  50. Public Sub GetIniInfo(strFile As String)
  51. On Error GoTo IniErr
  52. ' First, we'll clear out the previous file on the node if
  53. ' There was one.
  54. Set nodCurrentProj = nodRoot
  55. frmMain.treMain.Nodes.Remove nodCurrentProj.Index
  56. ' Make the root node the name of the file
  57. addRoot vFileName
  58.  
  59. Dim intG As Long
  60. Dim strline As String
  61. Dim strLeft As String
  62. Dim strRight As String
  63.     Open strFile For Input As #1
  64.         Do While Not EOF(1)
  65.             Line Input #1, strline
  66.             strline = UCase(strline)
  67.             strLeft = strline
  68.             strRight = strline
  69.                 If Left(strline, 1) = "[" Then ' This is a Key in the INI file
  70.                     strline = Right(strline, Len(strline) - 1)
  71.                     strline = Left(strline, Len(strline) - 1)
  72.                     addSec strline
  73.                 ElseIf InStr(strline, "=") Then
  74.                     For intG = 1 To Len(strline)
  75.                         strLeft = Left(strLeft, Len(strLeft) - 1)
  76.                         If InStr(strLeft, "=") Then
  77.                             ' Continue removing characters
  78.                         Else
  79.                             ' We have what we need, let's get out of the for/next loop
  80.                             addKey strLeft
  81.                             Exit For
  82.                         End If
  83.                     Next intG
  84.                     For intG = 1 To Len(strline)
  85.                         strRight = Right(strRight, Len(strRight) - 1)
  86.                         If InStr(strRight, "=") Then
  87.                             ' Continue removing characters
  88.                         Else
  89.                             addValue strRight
  90.                             Exit For
  91.                         End If
  92.                     Next intG
  93.                 End If
  94.     Loop
  95.     Close #1
  96.     nodRoot.Expanded = True
  97. Exit Sub
  98. IniErr:
  99. ' Error number 91 will happen when the program is first run
  100. ' This is because there is nothing on the nodes when it
  101. ' Starts up.
  102. If Err.Number = 91 Then
  103.     Resume Next
  104. Else
  105.     MsgBox "An unknown error has occured which will result in termination of this program." _
  106.     & Chr(10) & Err.Number & Chr(10) & Err.Description, vbOKOnly + vbCritical, "Fatal Error"
  107.     Unload frmMain
  108.     Set frmMain = Nothing
  109.     End
  110. End If
  111. End Sub
  112.  
  113.  
  114. ' ***************************************************
  115. 'Tree Node Code
  116.  
  117. Public Sub addRoot(strline As String)
  118.   'Set up the root node as the CurrentFileName
  119.   Set nodRoot = frmMain.treMain.Nodes.Add(, , "R", strline, 5)
  120.   nodRoot.Tag = "Root"
  121. End Sub
  122. Public Sub addSec(strline As String)
  123. ' Adds the section of an INI to the treenode - ie [SAMPLE]
  124.   Set nodSec = frmMain.treMain.Nodes.Add _
  125.     (nodRoot, tvwChild, , strline, 4)
  126.   nodSec.Tag = "Section"
  127. End Sub
  128. Public Sub addKey(strline As String)
  129.   ' Adds the Key of an INI to the treenode ie Setting=
  130.   Set nodKey = _
  131.     frmMain.treMain.Nodes.Add _
  132.     (nodSec, tvwChild, , strline, 2)
  133.   nodKey.Tag = "Key"
  134. End Sub
  135. Public Sub addValue(strline As String)
  136. ' Adds the Value of the Key to treenode - ie Setting=1
  137.   Set nodValue = frmMain.treMain.Nodes.Add(nodKey, tvwChild, , strline, 1)
  138.   nodValue.Tag = "Value"
  139. End Sub
  140.