home *** CD-ROM | disk | FTP | other *** search
/ Mastering Visual Basic 6 / mastvb6.iso / ch_code / ch08 / globe / tview.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1996-04-24  |  26.2 KB  |  731 lines

  1. VERSION 5.00
  2. Object = "{6B7E6392-850A-101B-AFC0-4210102A8DA7}#2.0#0"; "MSCOMCTL.OCX"
  3. Begin VB.Form GlobeForm 
  4.    Appearance      =   0  'Flat
  5.    BackColor       =   &H80000000&
  6.    Caption         =   "TreeView Demo (with unique keys)"
  7.    ClientHeight    =   6630
  8.    ClientLeft      =   165
  9.    ClientTop       =   735
  10.    ClientWidth     =   8430
  11.    LinkTopic       =   "Form1"
  12.    ScaleHeight     =   6630
  13.    ScaleWidth      =   8430
  14.    StartUpPosition =   3  'Windows Default
  15.    Begin VB.Frame Frame2 
  16.       Height          =   6480
  17.       Left            =   5280
  18.       TabIndex        =   8
  19.       Top             =   0
  20.       Width           =   3015
  21.       Begin VB.ListBox List1 
  22.          BeginProperty Font 
  23.             Name            =   "Verdana"
  24.             Size            =   9
  25.             Charset         =   0
  26.             Weight          =   400
  27.             Underline       =   0   'False
  28.             Italic          =   0   'False
  29.             Strikethrough   =   0   'False
  30.          EndProperty
  31.          Height          =   3210
  32.          Left            =   165
  33.          TabIndex        =   13
  34.          Top             =   240
  35.          Width           =   2715
  36.       End
  37.       Begin VB.CommandButton ListCities 
  38.          Caption         =   "List Cities"
  39.          BeginProperty Font 
  40.             Name            =   "Verdana"
  41.             Size            =   9.75
  42.             Charset         =   0
  43.             Weight          =   400
  44.             Underline       =   0   'False
  45.             Italic          =   0   'False
  46.             Strikethrough   =   0   'False
  47.          EndProperty
  48.          Height          =   480
  49.          Left            =   165
  50.          TabIndex        =   12
  51.          Top             =   5730
  52.          Width           =   2715
  53.       End
  54.       Begin VB.CommandButton ListContinents 
  55.          Caption         =   "List Continents"
  56.          BeginProperty Font 
  57.             Name            =   "Verdana"
  58.             Size            =   9.75
  59.             Charset         =   0
  60.             Weight          =   400
  61.             Underline       =   0   'False
  62.             Italic          =   0   'False
  63.             Strikethrough   =   0   'False
  64.          EndProperty
  65.          Height          =   480
  66.          Left            =   165
  67.          TabIndex        =   11
  68.          Top             =   4455
  69.          Width           =   2715
  70.       End
  71.       Begin VB.CommandButton ListCountries 
  72.          Caption         =   "List Countries"
  73.          BeginProperty Font 
  74.             Name            =   "Verdana"
  75.             Size            =   9.75
  76.             Charset         =   0
  77.             Weight          =   400
  78.             Underline       =   0   'False
  79.             Italic          =   0   'False
  80.             Strikethrough   =   0   'False
  81.          EndProperty
  82.          Height          =   480
  83.          Left            =   165
  84.          TabIndex        =   10
  85.          Top             =   5100
  86.          Width           =   2715
  87.       End
  88.       Begin VB.CommandButton FindCity 
  89.          Caption         =   "Find City"
  90.          BeginProperty Font 
  91.             Name            =   "Verdana"
  92.             Size            =   9.75
  93.             Charset         =   0
  94.             Weight          =   400
  95.             Underline       =   0   'False
  96.             Italic          =   0   'False
  97.             Strikethrough   =   0   'False
  98.          EndProperty
  99.          Height          =   480
  100.          Left            =   165
  101.          TabIndex        =   9
  102.          Top             =   3855
  103.          Width           =   2715
  104.       End
  105.    End
  106.    Begin VB.CommandButton ExpandNodeBttn 
  107.       Caption         =   "Expand Current Node"
  108.       BeginProperty Font 
  109.          Name            =   "Verdana"
  110.          Size            =   9.75
  111.          Charset         =   0
  112.          Weight          =   400
  113.          Underline       =   0   'False
  114.          Italic          =   0   'False
  115.          Strikethrough   =   0   'False
  116.       EndProperty
  117.       Height          =   465
  118.       Left            =   2655
  119.       TabIndex        =   7
  120.       Top             =   3540
  121.       Width           =   2400
  122.    End
  123.    Begin VB.CommandButton DeleteNodeBttn 
  124.       Caption         =   "Delete Current Node"
  125.       BeginProperty Font 
  126.          Name            =   "Verdana"
  127.          Size            =   9.75
  128.          Charset         =   0
  129.          Weight          =   400
  130.          Underline       =   0   'False
  131.          Italic          =   0   'False
  132.          Strikethrough   =   0   'False
  133.       EndProperty
  134.       Height          =   465
  135.       Left            =   180
  136.       TabIndex        =   6
  137.       Top             =   3540
  138.       Width           =   2400
  139.    End
  140.    Begin VB.CommandButton AddEntry 
  141.       Caption         =   "Add this Node"
  142.       BeginProperty Font 
  143.          Name            =   "Verdana"
  144.          Size            =   9.75
  145.          Charset         =   0
  146.          Weight          =   400
  147.          Underline       =   0   'False
  148.          Italic          =   0   'False
  149.          Strikethrough   =   0   'False
  150.       EndProperty
  151.       Height          =   465
  152.       Left            =   2880
  153.       TabIndex        =   4
  154.       Top             =   5850
  155.       Width           =   2055
  156.    End
  157.    Begin VB.TextBox Text3 
  158.       BeginProperty Font 
  159.          Name            =   "Verdana"
  160.          Size            =   9
  161.          Charset         =   0
  162.          Weight          =   400
  163.          Underline       =   0   'False
  164.          Italic          =   0   'False
  165.          Strikethrough   =   0   'False
  166.       EndProperty
  167.       Height          =   330
  168.       Left            =   2850
  169.       TabIndex        =   3
  170.       Top             =   5250
  171.       Width           =   2055
  172.    End
  173.    Begin VB.TextBox Text2 
  174.       BeginProperty Font 
  175.          Name            =   "Verdana"
  176.          Size            =   9
  177.          Charset         =   0
  178.          Weight          =   400
  179.          Underline       =   0   'False
  180.          Italic          =   0   'False
  181.          Strikethrough   =   0   'False
  182.       EndProperty
  183.       Height          =   330
  184.       Left            =   1665
  185.       TabIndex        =   2
  186.       Top             =   4815
  187.       Width           =   2055
  188.    End
  189.    Begin VB.TextBox Text1 
  190.       BeginProperty Font 
  191.          Name            =   "Verdana"
  192.          Size            =   9
  193.          Charset         =   0
  194.          Weight          =   400
  195.          Underline       =   0   'False
  196.          Italic          =   0   'False
  197.          Strikethrough   =   0   'False
  198.       EndProperty
  199.       Height          =   330
  200.       Left            =   345
  201.       TabIndex        =   1
  202.       Top             =   4365
  203.       Width           =   2055
  204.    End
  205.    Begin ComctlLib.TreeView TreeView1 
  206.       Height          =   3255
  207.       Left            =   165
  208.       TabIndex        =   0
  209.       Top             =   165
  210.       Width           =   4890
  211.       _ExtentX        =   8625
  212.       _ExtentY        =   5741
  213.       _Version        =   393217
  214.       HideSelection   =   0   'False
  215.       LabelEdit       =   1
  216.       Sorted          =   -1  'True
  217.       Style           =   6
  218.       HotTracking     =   -1  'True
  219.       Appearance      =   1
  220.       BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
  221.          Name            =   "Verdana"
  222.          Size            =   9
  223.          Charset         =   0
  224.          Weight          =   400
  225.          Underline       =   0   'False
  226.          Italic          =   0   'False
  227.          Strikethrough   =   0   'False
  228.       EndProperty
  229.       _Nodes          =   "TView.frx":0000
  230.    End
  231.    Begin VB.Frame Frame1 
  232.       Height          =   2430
  233.       Left            =   150
  234.       TabIndex        =   5
  235.       Top             =   4050
  236.       Width           =   4965
  237.       Begin VB.Line Line1 
  238.          X1              =   375
  239.          X2              =   375
  240.          Y1              =   675
  241.          Y2              =   1350
  242.       End
  243.       Begin VB.Line Line2 
  244.          X1              =   1530
  245.          X2              =   375
  246.          Y1              =   900
  247.          Y2              =   900
  248.       End
  249.       Begin VB.Line Line4 
  250.          X1              =   2715
  251.          X2              =   360
  252.          Y1              =   1350
  253.          Y2              =   1350
  254.       End
  255.    End
  256.    Begin ComctlLib.ImageList ImageList1 
  257.       Left            =   -15
  258.       Top             =   3705
  259.       _ExtentX        =   1005
  260.       _ExtentY        =   1005
  261.       BackColor       =   -2147483643
  262.       ImageWidth      =   32
  263.       ImageHeight     =   32
  264.       MaskColor       =   12632256
  265.       _Version        =   393216
  266.       BeginProperty Images {2C247F25-8591-11D1-B16A-00C0F0283628} 
  267.          NumListImages   =   5
  268.          BeginProperty ListImage1 {2C247F27-8591-11D1-B16A-00C0F0283628} 
  269.             Picture         =   "TView.frx":0028
  270.             Key             =   ""
  271.          EndProperty
  272.          BeginProperty ListImage2 {2C247F27-8591-11D1-B16A-00C0F0283628} 
  273.             Picture         =   "TView.frx":047C
  274.             Key             =   "Snow"
  275.             Object.Tag             =   "Weather"
  276.          EndProperty
  277.          BeginProperty ListImage3 {2C247F27-8591-11D1-B16A-00C0F0283628} 
  278.             Picture         =   "TView.frx":08D0
  279.             Key             =   ""
  280.          EndProperty
  281.          BeginProperty ListImage4 {2C247F27-8591-11D1-B16A-00C0F0283628} 
  282.             Picture         =   "TView.frx":0D24
  283.             Key             =   ""
  284.          EndProperty
  285.          BeginProperty ListImage5 {2C247F27-8591-11D1-B16A-00C0F0283628} 
  286.             Picture         =   "TView.frx":1178
  287.             Key             =   ""
  288.          EndProperty
  289.       EndProperty
  290.    End
  291.    Begin VB.Menu FileMenu 
  292.       Caption         =   "File"
  293.       Begin VB.Menu FileLoad 
  294.          Caption         =   "Load Control"
  295.       End
  296.       Begin VB.Menu FileSave 
  297.          Caption         =   "Save Control"
  298.       End
  299.       Begin VB.Menu sep1 
  300.          Caption         =   "-"
  301.       End
  302.       Begin VB.Menu FileExit 
  303.          Caption         =   "Exit"
  304.       End
  305.    End
  306. Attribute VB_Name = "GlobeForm"
  307. Attribute VB_GlobalNameSpace = False
  308. Attribute VB_Creatable = False
  309. Attribute VB_PredeclaredId = True
  310. Attribute VB_Exposed = False
  311. '  ******************************
  312. '  ******************************
  313. '  ** MASTERING VB6            **
  314. '  ** by Evangelos Petroutos   **
  315. '  ** SYBEX, 1998              **
  316. '  ******************************
  317. '  ******************************
  318. Option Explicit
  319. Private Sub AddEntry_Click()
  320. Dim newNode As Node
  321. Dim NodeContinent As Node, NodeCountry As Node, NodeCity As Node
  322. On Error Resume Next
  323.     Text1.Text = Trim(Text1.Text)
  324.     Text2.Text = Trim(Text2.Text)
  325.     Text3.Text = Trim(Text3.Text)
  326.     If Trim(Text1.Text) = "" Then
  327.         MsgBox "You didn't supply a continent name"
  328.         Exit Sub
  329.     End If
  330.     Set newNode = TreeView1.Nodes.Item(UCase$(Text1.Text))
  331.     If Error Then
  332.         Set newNode = TreeView1.Nodes.Add("GLOBE", tvwChild, UCase$(Text1.Text), Text1.Text, 2)
  333.         newNode.Tag = "Continents"
  334.     End If
  335.     If Trim(Text2.Text) = "" Then Exit Sub
  336.     Set newNode = TreeView1.Nodes.Item(UCase$(Text2.Text))
  337.     If Error Then
  338.         Set newNode = TreeView1.Nodes.Add(UCase$(Text1.Text), tvwChild, UCase$(Text2.Text), Text2.Text, 3)
  339.         newNode.Tag = "Countries"
  340.     End If
  341.     If Trim(Text3.Text) = "" Then Exit Sub
  342.     Set newNode = TreeView1.Nodes.Item(UCase$(Text3.Text))
  343.     If Error Then
  344.         Set newNode = TreeView1.Nodes.Add(UCase$(Text2.Text), tvwChild, UCase$(Text3.Text), Text3.Text)
  345.         newNode.Tag = "Cities"
  346.     End If
  347.     TreeView1.SelectedItem = newNode
  348.     TreeView1.SelectedItem.EnsureVisible
  349. End Sub
  350. Private Sub DeleteNodeBttn_Click()
  351.     TreeView1.Nodes.Remove (TreeView1.SelectedItem.Index)
  352.     Text1.Text = ""
  353.     Text2.Text = ""
  354.     Text3.Text = ""
  355. End Sub
  356. Private Sub ExpandNodeBttn_Click()
  357.     TreeView1.SelectedItem.Expanded = True
  358. End Sub
  359. Private Sub FileExit_Click()
  360.     End
  361. End Sub
  362. Private Sub FileLoad_Click()
  363. Dim FNum As Integer
  364. Dim Nd As Node
  365. Dim level1 As String, level2 As String
  366. Dim key As String
  367. Dim nodeText As String
  368. TreeView1.Nodes.Clear
  369. ' set up the ListImage object
  370. Dim Images As ListImage
  371.     Set Images = ImageList1.ListImages.Add(, , LoadPicture(App.Path & "\cont.bmp"))
  372.     Set Images = ImageList1.ListImages.Add(, , LoadPicture(App.Path & "\country.bmp"))
  373.     Set Images = ImageList1.ListImages.Add(, , LoadPicture(App.Path & "\city.bmp"))
  374.     TreeView1.ImageList = ImageList1
  375. ' THERE'S NO NEED TO DO ANYTHING ABOUT SORTING KEYS, BECAUSE
  376. ' THE ITEMS WERE SORTED WHEN THE TREEVIEW CONTROL WAS SAVED
  377.     FNum = FreeFile()
  378.     Set Nd = TreeView1.Nodes.Add(, , "GLOBE", "Globe", 1)
  379.     Nd.Tag = "GLOBE"
  380.     Nd.Sorted = True
  381.     Open App.Path & "\Globe.txt" For Input As #FNum
  382.     While Not EOF(FNum)
  383.         Input #FNum, nodeText
  384.         key = UCase(Trim(nodeText))
  385.         If Left(nodeText, 3) = "   " Then
  386.             Set Nd = TreeView1.Nodes.Add(level2, tvwChild, key, Trim(nodeText), 3)
  387.             Nd.Tag = "Cities"
  388.         ElseIf Left(nodeText, 2) = "  " Then
  389.             level2 = key
  390.             Set Nd = TreeView1.Nodes.Add(level1, tvwChild, key, Trim(nodeText), 2)
  391.             Nd.Tag = "Countries"
  392.         ElseIf Left(nodeText, 1) = " " Then
  393.             level1 = key
  394.             Set Nd = TreeView1.Nodes.Add("GLOBE", tvwChild, key, Trim(nodeText), 1)
  395.             Nd.Tag = "Continents"
  396.         End If
  397.     Wend
  398.     Close #FNum
  399. End Sub
  400. Private Sub FileSave_Click()
  401. Dim Nd As Node, countryNd As Node, continentNd As Node, cityNd As Node
  402. Dim continent As Integer, continents As Integer
  403. Dim country As Integer, countries As Integer
  404. Dim city As Integer, cities As Integer
  405. Dim FNum As Integer
  406.     FNum = FreeFile()
  407.     Open App.Path & "\Globe.txt" For Output As #FNum
  408.     Set Nd = TreeView1.Nodes.Item("GLOBE")
  409. Debug.Print Nd.Text
  410.     Write #FNum, Nd.Text
  411.     continents = Nd.Children
  412.     Set continentNd = Nd.Child
  413.     For continent = 1 To continents
  414. Debug.Print continentNd.Text
  415.         Write #FNum, " " & continentNd.Text
  416.         countries = continentNd.Children
  417.         Set countryNd = continentNd.Child
  418.         For country = 1 To countries
  419. Debug.Print "   " & countryNd.Text
  420.             Write #FNum, "  " & countryNd.Text
  421.             cities = countryNd.Children
  422.             Set cityNd = countryNd.Child
  423.             For city = 1 To cities
  424. Debug.Print "      " & cityNd.Text
  425.                 Write #FNum, "   " & cityNd.Text
  426.                 Set cityNd = cityNd.Next
  427.             Next
  428.             Set countryNd = countryNd.Next
  429.         Next
  430.         Set continentNd = continentNd.Next
  431.     Next
  432.     Close #FNum
  433. End Sub
  434. Private Sub FindCity_Click()
  435. Dim Nd As Node, ParentNd As Node
  436. Dim NodeName As String, NodeKey As String
  437. On Error GoTo NoCity
  438.     NodeName = InputBox("Enter name of node")
  439.     NodeKey = UCase$(Trim(NodeName))
  440.     Set Nd = TreeView1.Nodes.Item(NodeKey)
  441.     TreeView1.SelectedItem = Nd
  442.     Set ParentNd = Nd.Parent
  443.     If Not IsNull(ParentNd) Then
  444.         NodeKey = UCase$(ParentNd.Text)
  445.         TreeView1.Nodes(NodeKey).Expanded = True
  446.     End If
  447.     Set ParentNd = ParentNd.Parent
  448.     If Not IsNull(ParentNd) Then
  449.         NodeKey = UCase$(ParentNd.Text)
  450.         TreeView1.Nodes(NodeKey).Expanded = True
  451.     End If
  452.     Set ParentNd = ParentNd.Parent
  453.     If Not IsNull(ParentNd) Then
  454.         NodeKey = UCase$(ParentNd.Text)
  455.         TreeView1.Nodes(NodeKey).Expanded = True
  456.     End If
  457.     Text3.Text = TreeView1.SelectedItem.Text
  458.     Text2.Text = TreeView1.SelectedItem.Parent.Text
  459.     Text1.Text = TreeView1.SelectedItem.Parent.Parent.Text
  460.     Exit Sub
  461. NoCity:
  462.     If Err.Number = 35601 Then
  463.         MsgBox "The city you requested does not exist"
  464.     Else
  465.         MsgBox "The key you supplied is not a city name"
  466.     End If
  467. End Sub
  468. Private Sub Form_Load()
  469. Dim Nd As Node
  470. ' set up the ListImage object
  471. ImageList1.ListImages.Add , , LoadPicture(App.Path & "\cont.bmp")
  472. ImageList1.ListImages.Add , , LoadPicture(App.Path & "\country.bmp")
  473. ImageList1.ListImages.Add , , LoadPicture(App.Path & "\city.bmp")
  474. TreeView1.ImageList = ImageList1
  475. ' now set up Treeview control
  476. Set Nd = TreeView1.Nodes.Add(, , "GLOBE", "Globe", 1)
  477. Nd.Tag = "GLOBE"
  478. Nd.Sorted = True
  479. Set Nd = TreeView1.Nodes.Add("GLOBE", tvwChild, "EUROPE", "EUROPE", 2)
  480. Nd.Tag = "Continents"
  481. Nd.Sorted = True    ' this statement sorts all countries under EUROPE
  482. Set Nd = TreeView1.Nodes.Add("GLOBE", tvwChild, "ASIA", "ASIA", 2)
  483. Nd.Tag = "Continents"
  484. Nd.Sorted = True    ' this statement sorts all countries under ASIA
  485. Set Nd = TreeView1.Nodes.Add("GLOBE", tvwChild, "AFRICA", "AFRICA", 2)
  486. Nd.Tag = "Continents"
  487. Nd.Sorted = True    ' ' this statement sorts all countries under AFRICA
  488. Set Nd = TreeView1.Nodes.Add("GLOBE", tvwChild, "AMERICA", "AMERICA", 2)
  489. Nd.Tag = "Continents"
  490. Nd.Sorted = True    ' this statement sorts all countries under AMERICA
  491. Set Nd = TreeView1.Nodes.Add("GLOBE", tvwChild, "OCEANIA", "OCEANIA", 2)
  492. Nd.Tag = "Continents"
  493. Nd.Sorted = True
  494. Set Nd = TreeView1.Nodes.Add("EUROPE", tvwChild, "GERMANY", "Germany", 3)
  495. Nd.Tag = "Countries"
  496. Nd.Sorted = True    ' this statement sorts all german cities
  497. Set Nd = TreeView1.Nodes.Add("GERMANY", tvwChild, "BERLIN", "Berlin")
  498. Nd.Tag = "Cities"
  499. Set Nd = TreeView1.Nodes.Add("GERMANY", tvwChild, "MUNICH", "Munich")
  500. Nd.Tag = "Cities"
  501. Set Nd = TreeView1.Nodes.Add("GERMANY", tvwChild, "BAYREUTH", "Bayreuth")
  502. Nd.Tag = "Cities"
  503. Set Nd = TreeView1.Nodes.Add("GERMANY", tvwChild, "FRANFURT", "Frankfurt")
  504. Nd.Tag = "Cities"
  505. Set Nd = TreeView1.Nodes.Add("EUROPE", tvwChild, "FRANCE", "France", 3)
  506. Nd.Tag = "Countries"
  507. Nd.Sorted = True    ' this statement sorts all french cities
  508. Set Nd = TreeView1.Nodes.Add("FRANCE", tvwChild, "PARIS", "Paris")
  509. Nd.Tag = "Cities"
  510. Set Nd = TreeView1.Nodes.Add("FRANCE", tvwChild, "NICE", "Nice")
  511. Nd.Tag = "Cities"
  512. Set Nd = TreeView1.Nodes.Add("FRANCE", tvwChild, "LYON", "Lyon")
  513. Nd.Tag = "Cities"
  514. Set Nd = TreeView1.Nodes.Add("EUROPE", tvwChild, "ITALY", "Italy", 3)
  515. Nd.Tag = "Countries"
  516. Nd.Sorted = True    ' this statement sorts all italian cities
  517. Set Nd = TreeView1.Nodes.Add("ITALY", tvwChild, "ROME", "Rome")
  518. Nd.Tag = "Cities"
  519. Set Nd = TreeView1.Nodes.Add("ITALY", tvwChild, "VENICE", "Venice")
  520. Nd.Tag = "Cities"
  521. Set Nd = TreeView1.Nodes.Add("ITALY", tvwChild, "NAPOLI", "Napoli")
  522. Nd.Tag = "Cities"
  523. Set Nd = TreeView1.Nodes.Add("ITALY", tvwChild, "FLORENCE", "Florence")
  524. Nd.Tag = "Cities"
  525. Set Nd = TreeView1.Nodes.Add("ITALY", tvwChild, "MILAN", "Milan")
  526. Nd.Tag = "Cities"
  527. Set Nd = TreeView1.Nodes.Add("EUROPE", tvwChild, "SPAIN", "Spain", 3)
  528. Nd.Tag = "Countries"
  529. Nd.Sorted = True    ' this statement sorts all spanish cities
  530. Set Nd = TreeView1.Nodes.Add("SPAIN", tvwChild, "MADRID", "Madrid")
  531. Nd.Tag = "Cities"
  532. Set Nd = TreeView1.Nodes.Add("SPAIN", tvwChild, "BARCELONA", "Barcelona")
  533. Nd.Tag = "Cities"
  534. Set Nd = TreeView1.Nodes.Add("SPAIN", tvwChild, "MALAGA", "Malaga")
  535. Nd.Tag = "Cities"
  536. Set Nd = TreeView1.Nodes.Add("ASIA", tvwChild, "CHINA", "China", 3)
  537. Nd.Tag = "Countries"
  538. Nd.Sorted = True
  539. Set Nd = TreeView1.Nodes.Add("CHINA", tvwChild, "BEJING", "Bejing")
  540. Nd.Tag = "Cities"
  541. Set Nd = TreeView1.Nodes.Add("CHINA", tvwChild, "NANJING", "Nanjing")
  542. Nd.Tag = "Cities"
  543. Set Nd = TreeView1.Nodes.Add("CHINA", tvwChild, "HONG KONG", "Hong Kong")
  544. Nd.Tag = "Cities"
  545. Set Nd = TreeView1.Nodes.Add("ASIA", tvwChild, "JAPAN", "Japan", 3)
  546. Nd.Tag = "Countries"
  547. Nd.Sorted = True
  548. Set Nd = TreeView1.Nodes.Add("JAPAN", tvwChild, "TOKYO", "Tokyo")
  549. Nd.Tag = "Cities"
  550. Set Nd = TreeView1.Nodes.Add("JAPAN", tvwChild, "OSAKA", "Osaka")
  551. Nd.Tag = "Cities"
  552. Set Nd = TreeView1.Nodes.Add("JAPAN", tvwChild, "KOBE", "Kobe")
  553. Nd.Tag = "Cities"
  554. Set Nd = TreeView1.Nodes.Add("JAPAN", tvwChild, "KYOTTO", "Kyotto")
  555. Nd.Tag = "Cities"
  556. Set Nd = TreeView1.Nodes.Add("JAPAN", tvwChild, "SAPPORO", "Sapporo")
  557. Nd.Tag = "Cities"
  558. Set Nd = TreeView1.Nodes.Add("AFRICA", tvwChild, "EGYPT", "Egypt", 3)
  559. Nd.Tag = "Countries"
  560. Nd.Sorted = True
  561. Set Nd = TreeView1.Nodes.Add("EGYPT", tvwChild, "CAIRO", "Cairo")
  562. Nd.Tag = "Cities"
  563. Set Nd = TreeView1.Nodes.Add("EGYPT", tvwChild, "ALEXANDRIA", "Alexandria")
  564. Nd.Tag = "Cities"
  565. Set Nd = TreeView1.Nodes.Add("AFRICA", tvwChild, "LIBYA", "Libya", 3)
  566. Nd.Tag = "Countries"
  567. Nd.Sorted = True
  568. Set Nd = TreeView1.Nodes.Add("LIBYA", tvwChild, "TRIPOLI", "Tripoli")
  569. Nd.Tag = "Cities"
  570. Set Nd = TreeView1.Nodes.Add("AFRICA", tvwChild, "SOUTH AFRICA", "South Africa", 3)
  571. Nd.Tag = "Countries"
  572. Nd.Sorted = True
  573. Set Nd = TreeView1.Nodes.Add("SOUTH AFRICA", tvwChild, "JOHANNESBURG", "Johannesburg")
  574. Nd.Tag = "Cities"
  575. Set Nd = TreeView1.Nodes.Add("SOUTH AFRICA", tvwChild, "PRETORIA", "Pretoria")
  576. Nd.Tag = "Cities"
  577. Set Nd = TreeView1.Nodes.Add("AFRICA", tvwChild, "ZIMBABWE", "Zimbabwe", 3)
  578. Nd.Tag = "Countries"
  579. Nd.Sorted = True
  580. Set Nd = TreeView1.Nodes.Add("ZIMBABWE", tvwChild, "HARARE", "Harare")
  581. Nd.Tag = "Cities"
  582. Set Nd = TreeView1.Nodes.Add("OCEANIA", tvwChild, "AUSTRALIA", "Australia", 3)
  583. Nd.Tag = "Countries"
  584. Nd.Sorted = True
  585. Set Nd = TreeView1.Nodes.Add("AUSTRALIA", tvwChild, "SINDEY", "Sidney")
  586. Nd.Tag = "Cities"
  587. Set Nd = TreeView1.Nodes.Add("AUSTRALIA", tvwChild, "MELBOURNE", "Melbourne")
  588. Nd.Tag = "Cities"
  589. Set Nd = TreeView1.Nodes.Add("AUSTRALIA", tvwChild, "ADELAIADE", "Adelaida")
  590. Nd.Tag = "Cities"
  591. Set Nd = TreeView1.Nodes.Add("AUSTRALIA", tvwChild, "BRISBANE", "Brisbane")
  592. Nd.Tag = "Cities"
  593. Set Nd = TreeView1.Nodes.Add("AUSTRALIA", tvwChild, "CANBERRA", "Canberra")
  594. Nd.Tag = "Cities"
  595. Set Nd = TreeView1.Nodes.Add("OCEANIA", tvwChild, "NEW ZEALAND", "New Zealand", 3)
  596. Nd.Tag = "Countries"
  597. Nd.Sorted = True
  598. Set Nd = TreeView1.Nodes.Add("NEW ZEALAND", tvwChild, "WANAKA", "Wanaka")
  599. Nd.Tag = "Cities"
  600. Set Nd = TreeView1.Nodes.Add("AMERICA", tvwChild, "USA", "USA", 3)
  601. Nd.Tag = "Countries"
  602. Nd.Sorted = True
  603. Set Nd = TreeView1.Nodes.Add("USA", tvwChild, "NEW YORK", "New York")
  604. Nd.Tag = "Cities"
  605. Set Nd = TreeView1.Nodes.Add("USA", tvwChild, "LAS VEGAS", "Las Vegas")
  606. Nd.Tag = "Cities"
  607. Set Nd = TreeView1.Nodes.Add("USA", tvwChild, "CHICAGO", "Chicago")
  608. Nd.Tag = "Cities"
  609. Set Nd = TreeView1.Nodes.Add("USA", tvwChild, "WASHINGTON", "Washington")
  610. Nd.Tag = "Cities"
  611. Set Nd = TreeView1.Nodes.Add("USA", tvwChild, "DURHAM", "Durham")
  612. Nd.Tag = "Cities"
  613. Set Nd = TreeView1.Nodes.Add("USA", tvwChild, "SAN FRANCISCO", "San Francisco")
  614. Nd.Tag = "Cities"
  615. Set Nd = TreeView1.Nodes.Add("AMERICA", tvwChild, "CANADA", "Canada", 3)
  616. Nd.Tag = "Countries"
  617. Nd.Sorted = True
  618. Set Nd = TreeView1.Nodes.Add("CANADA", tvwChild, "TORONTO", "Toronto")
  619. Nd.Tag = "Cities"
  620. Set Nd = TreeView1.Nodes.Add("CANADA", tvwChild, "VANCOUVER", "Vancouver")
  621. Nd.Tag = "Cities"
  622. Set Nd = TreeView1.Nodes.Add("CANADA", tvwChild, "MONTREAL", "Montreal")
  623. Nd.Tag = "Cities"
  624. Set Nd = TreeView1.Nodes.Add("CANADA", tvwChild, "HALIFAX", "Halifax")
  625. Nd.Tag = "Cities"
  626. Set Nd = TreeView1.Nodes.Add("CANADA", tvwChild, "CALGARY", "Calgary")
  627. Nd.Tag = "Cities"
  628. Set Nd = TreeView1.Nodes.Add("AMERICA", tvwChild, "MEXICO", "Mexico", 3)
  629. Nd.Tag = "Countries"
  630. Nd.Sorted = True
  631. Set Nd = TreeView1.Nodes.Add("MEXICO", tvwChild, "MEXICO CITY", "Mexico City")
  632. Nd.Tag = "Cities"
  633. Set Nd = TreeView1.Nodes.Add("AMERICA", tvwChild, "ARGENTINA", "Argentina", 3)
  634. Nd.Tag = "Countries"
  635. Nd.Sorted = True
  636. Set Nd = TreeView1.Nodes.Add("ARGENTINA", tvwChild, "BUENOS AIRES", "Buenos Aires")
  637. Nd.Tag = "Cities"
  638. End Sub
  639. Private Sub ListCities_Click()
  640. Dim Nd As Node, countryNd As Node, continentNd As Node, cityNd As Node
  641. Dim continent As Integer, continents As Integer
  642. Dim country As Integer, countries As Integer
  643. Dim city As Integer, cities As Integer
  644.     List1.Clear
  645.     Set Nd = TreeView1.Nodes.Item("GLOBE")
  646.     continents = Nd.Children
  647.     Set continentNd = Nd.Child
  648.     For continent = 1 To continents
  649.         countries = continentNd.Children
  650.         Set countryNd = continentNd.Child
  651.         For country = 1 To countries
  652.             cities = countryNd.Children
  653.             Set cityNd = countryNd.Child
  654.             For city = 1 To cities
  655.                 List1.AddItem cityNd.Text
  656.                 Set cityNd = cityNd.Next
  657.             Next
  658.             Set countryNd = countryNd.Next
  659.         Next
  660.         Set continentNd = continentNd.Next
  661.     Next
  662. End Sub
  663. Private Sub ListContinents_Click()
  664. Dim Nd As Node, childNd As Node
  665. Dim continent As Integer, continents As Integer
  666.     List1.Clear
  667.     Set Nd = TreeView1.Nodes.Item("GLOBE")
  668.     continents = Nd.Children
  669.     Set childNd = Nd.Child
  670.     For continent = 1 To continents
  671.         List1.AddItem childNd.Text
  672.         Set childNd = childNd.Next
  673.     Next
  674. End Sub
  675. Private Sub ListCountries_Click()
  676. Dim Nd As Node, countryNd As Node, continentNd As Node
  677. Dim continent As Integer, continents As Integer
  678. Dim country As Integer, countries As Integer
  679.     List1.Clear
  680.     Set Nd = TreeView1.Nodes.Item("GLOBE")
  681.     continents = Nd.Children
  682.     Set continentNd = Nd.Child
  683.     For continent = 1 To continents
  684.         countries = continentNd.Children
  685.         Set countryNd = continentNd.Child
  686.         For country = 1 To countries
  687.             List1.AddItem countryNd.Text
  688.             Set countryNd = countryNd.Next
  689.         Next
  690.         Set continentNd = continentNd.Next
  691.     Next
  692. End Sub
  693. Private Sub TreeView1_NodeClick(ByVal Node As ComctlLib.Node)
  694. Dim Nd As Node, childNd As Node
  695. Dim i As Integer
  696.     Text1.Text = ""
  697.     Text2.Text = ""
  698.     Text3.Text = ""
  699.     Set Nd = Node
  700.     Me.Caption = Nd.FullPath
  701.     Nd.Expanded = Not Nd.Expanded
  702. ' Uncomment the following line to display the children
  703. ' of the selected node in the ListBox control
  704. '    If Nd.Children > 0 Then
  705. '        List1.Clear
  706. '        Set childNd = Nd.Child
  707. '        For i = 0 To Nd.Children - 1
  708. '            List1.AddItem childNd.Text
  709. '            Set childNd = childNd.Next
  710. '        Next
  711. '     End If
  712.      Set Nd = Node
  713.      If Nd.Tag = "GLOBE" Then Exit Sub
  714.      If Nd.Tag = "Cities" Then
  715.         Text3.Text = Nd.Text
  716.         Set Nd = Nd.Parent
  717.         Text2.Text = Nd.Text
  718.         Set Nd = Nd.Parent
  719.         Text1.Text = Nd.Text
  720.      ElseIf Nd.Tag = "Countries" Then
  721.         Text3.Text = ""
  722.         Text2.Text = Nd.Text
  723.         Set Nd = Nd.Parent
  724.         Text1.Text = Nd.Text
  725.      Else
  726.          Text1.Text = Nd.Text
  727.          Text2.Text = ""
  728.          Text3.Text = ""
  729.      End If
  730. End Sub
  731.