home *** CD-ROM | disk | FTP | other *** search
/ Programming Tool Box / SIMS_2.iso / vb_code1 / assocc1 / example.frm < prev    next >
Text File  |  1994-01-09  |  4KB  |  167 lines

  1. VERSION 2.00
  2. Begin Form frmMain 
  3.    BorderStyle     =   1  'Fixed Single
  4.    Caption         =   "Assoc Example"
  5.    ClientHeight    =   2688
  6.    ClientLeft      =   4032
  7.    ClientTop       =   3000
  8.    ClientWidth     =   2016
  9.    Height          =   3108
  10.    Left            =   3984
  11.    LinkTopic       =   "Form1"
  12.    MaxButton       =   0   'False
  13.    MinButton       =   0   'False
  14.    ScaleHeight     =   2688
  15.    ScaleWidth      =   2016
  16.    Top             =   2628
  17.    Width           =   2112
  18.    Begin CommandButton btnExit 
  19.       Caption         =   "Exit"
  20.       Height          =   252
  21.       Left            =   1320
  22.       TabIndex        =   2
  23.       Top             =   2280
  24.       Width           =   612
  25.    End
  26.    Begin CommandButton btnAssoc 
  27.       Caption         =   "Assoc"
  28.       Height          =   372
  29.       Left            =   120
  30.       TabIndex        =   1
  31.       Top             =   2160
  32.       Width           =   852
  33.    End
  34.    Begin CommandButton btnArray 
  35.       Caption         =   "Array"
  36.       Height          =   372
  37.       Left            =   120
  38.       TabIndex        =   0
  39.       Top             =   1680
  40.       Width           =   852
  41.    End
  42.    Begin ASSOC Addrs 
  43.       Delimiter       =   "="
  44.       Height          =   336
  45.       Left            =   1560
  46.       Top             =   1680
  47.       Width           =   336
  48.    End
  49.    Begin Label lblExplain2 
  50.       AutoSize        =   -1  'True
  51.       Caption         =   "The output appears in the Debug window."
  52.       Height          =   384
  53.       Left            =   120
  54.       TabIndex        =   4
  55.       Top             =   960
  56.       Width           =   1812
  57.       WordWrap        =   -1  'True
  58.    End
  59.    Begin Label lblExplain1 
  60.       AutoSize        =   -1  'True
  61.       Caption         =   "Click on Array or Assoc to load names and addresses."
  62.       Height          =   576
  63.       Left            =   120
  64.       TabIndex        =   3
  65.       Top             =   120
  66.       Width           =   1812
  67.       WordWrap        =   -1  'True
  68.    End
  69. End
  70. Option Explicit
  71.  
  72. Dim Surnames(1 To 100) As String, Addresses(1 To 100) As String
  73.  
  74. Sub Addrs_Enumerate (Key As String, Value As String)
  75.     Debug.Print Key, Value
  76. End Sub
  77.  
  78. Sub btnArray_Click ()
  79.     Call TryArray
  80. End Sub
  81.  
  82. Sub btnAssoc_Click ()
  83.     Call TryAssoc
  84. End Sub
  85.  
  86. Sub btnExit_Click ()
  87.     Unload frmMain
  88. End Sub
  89.  
  90. Sub TryArray ()
  91.  
  92.     Dim DataFile As String
  93.     Dim Surname As String, Address As String
  94.     Dim I As Integer, N As Integer
  95.  
  96.     ' Set the full path for the data file
  97.     If Right$(App.Path, 1) = "\" Then
  98.     DataFile = App.Path & "ADDR.DAT"
  99.     Else
  100.     DataFile = App.Path & "\" & "ADDR.DAT"
  101.     End If
  102.  
  103.     ' Read in the names and addresses
  104.     Open DataFile For Input As #1
  105.     For I = 1 To 100
  106.     If EOF(1) Then N = I - 1: Exit For
  107.     Input #1, Surname
  108.     If EOF(1) Then N = I - 1: Exit For
  109.     ' .. in case there was a blank line
  110.     Input #1, Address
  111.     Surnames(I) = Surname
  112.     Addresses(I) = Address
  113.     Next I
  114.     Close #1
  115.  
  116.     ' Dump the arrays to the Debug window
  117.     Debug.Print
  118.     Debug.Print "Array ..."
  119.     For I = 1 To N
  120.     Debug.Print Surnames(I), Addresses(I)
  121.     Next I
  122.  
  123. End Sub
  124.  
  125. Sub TryAssoc ()
  126.  
  127.     Dim DataFile As String
  128.     Dim Surname As String, Address As String
  129.     Const ASSOC_ENUMERATE = 0
  130.  
  131.     ' Set the full path for the data file
  132.     If Right$(App.Path, 1) = "\" Then
  133.     DataFile = App.Path & "ADDR.DAT"
  134.     Else
  135.     DataFile = App.Path & "\" & "ADDR.DAT"
  136.     End If
  137.  
  138.     ' Read in the names and addresses
  139.     Open DataFile For Input As #1
  140.     Do Until EOF(1)
  141.     Input #1, Surname
  142.     If EOF(1) Then Exit Do
  143.     ' .. in case there was a blank line
  144.     Input #1, Address
  145.     Addrs.Key = Surname
  146.     Addrs.Value = Address
  147.     Loop
  148.     Close #1
  149.  
  150.     ' Dump the arrays to the Debug window
  151.     Debug.Print
  152.     Debug.Print "Assoc ..."
  153.     Addrs.Key = ""
  154.     Do
  155.     Addrs.Key = Addrs.NextKey
  156.     If Addrs.Key = "" Then Exit Do
  157.     Debug.Print Addrs.Key, Addrs.Value
  158.     Loop
  159.  
  160.     ' Now dump them again using the Enumerate event
  161.     Debug.Print
  162.     Debug.Print "Assoc using Enumerate ..."
  163.     Addrs.Action=ASSOC_ENUMERATE
  164.  
  165. End Sub
  166.  
  167.