home *** CD-ROM | disk | FTP | other *** search
/ Programming Tool Box / SIMS_2.iso / tool / various / assoc / example.txt < prev    next >
Text File  |  1995-02-26  |  2KB  |  98 lines

  1. Option Explicit
  2.  
  3. Dim Surnames(1 To 100) As String, Addresses(1 To 100) As String
  4.  
  5. Sub Addrs_Enumerate (Key As String, Value As String)
  6.     Debug.Print Key, Value
  7. End Sub
  8.  
  9. Sub btnArray_Click ()
  10.     Call TryArray
  11. End Sub
  12.  
  13. Sub btnAssoc_Click ()
  14.     Call TryAssoc
  15. End Sub
  16.  
  17. Sub btnExit_Click ()
  18.     Unload frmMain
  19. End Sub
  20.  
  21. Sub TryArray ()
  22.  
  23.     Dim DataFile As String
  24.     Dim Surname As String, Address As String
  25.     Dim I As Integer, N As Integer
  26.  
  27.     ' Set the full path for the data file
  28.     If Right$(App.Path, 1) = "\" Then
  29.     DataFile = App.Path & "ADDR.DAT"
  30.     Else
  31.     DataFile = App.Path & "\" & "ADDR.DAT"
  32.     End If
  33.  
  34.     ' Read in the names and addresses
  35.     Open DataFile For Input As #1
  36.     For I = 1 To 100
  37.     If EOF(1) Then N = I - 1: Exit For
  38.     Input #1, Surname
  39.     If EOF(1) Then N = I - 1: Exit For
  40.     ' .. in case there was a blank line
  41.     Input #1, Address
  42.     Surnames(I) = Surname
  43.     Addresses(I) = Address
  44.     Next I
  45.     Close #1
  46.  
  47.     ' Dump the arrays to the Debug window
  48.     Debug.Print
  49.     Debug.Print "Array ..."
  50.     For I = 1 To N
  51.     Debug.Print Surnames(I), Addresses(I)
  52.     Next I
  53.  
  54. End Sub
  55.  
  56. Sub TryAssoc ()
  57.  
  58.     Dim DataFile As String
  59.     Dim Surname As String, Address As String
  60.     Const ASSOC_ENUMERATE = 0
  61.  
  62.     ' Set the full path for the data file
  63.     If Right$(App.Path, 1) = "\" Then
  64.     DataFile = App.Path & "ADDR.DAT"
  65.     Else
  66.     DataFile = App.Path & "\" & "ADDR.DAT"
  67.     End If
  68.  
  69.     ' Read in the names and addresses
  70.     Open DataFile For Input As #1
  71.     Do Until EOF(1)
  72.     Input #1, Surname
  73.     If EOF(1) Then Exit Do
  74.     ' .. in case there was a blank line
  75.     Input #1, Address
  76.     Addrs.Key = Surname
  77.     Addrs.Value = Address
  78.     Loop
  79.     Close #1
  80.  
  81.     ' Dump the arrays to the Debug window
  82.     Debug.Print
  83.     Debug.Print "Assoc ..."
  84.     Addrs.Key = ""
  85.     Do
  86.     Addrs.Key = Addrs.NextKey
  87.     If Addrs.Key = "" Then Exit Do
  88.     Debug.Print Addrs.Key, Addrs.Value
  89.     Loop
  90.  
  91.     ' Now dump them again using the Enumerate event
  92.     Debug.Print
  93.     Debug.Print "Assoc using Enumerate ..."
  94.     Addrs.Action = ASSOC_ENUMERATE
  95.  
  96. End Sub
  97.  
  98.