home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / VISUAL_B / CODIGO_1 / ASSOCC1 / EXAMPLE.FRM (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1994-01-09  |  4.1 KB  |  147 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. Option Explicit
  70. Dim Surnames(1 To 100) As String, Addresses(1 To 100) As String
  71. Sub Addrs_Enumerate (Key As String, Value As String)
  72.     Debug.Print Key, Value
  73. End Sub
  74. Sub btnArray_Click ()
  75.     Call TryArray
  76. End Sub
  77. Sub btnAssoc_Click ()
  78.     Call TryAssoc
  79. End Sub
  80. Sub btnExit_Click ()
  81.     Unload frmMain
  82. End Sub
  83. Sub TryArray ()
  84.     Dim DataFile As String
  85.     Dim Surname As String, Address As String
  86.     Dim I As Integer, N As Integer
  87.     ' Set the full path for the data file
  88.     If Right$(App.Path, 1) = "\" Then
  89.     DataFile = App.Path & "ADDR.DAT"
  90.     Else
  91.     DataFile = App.Path & "\" & "ADDR.DAT"
  92.     End If
  93.     ' Read in the names and addresses
  94.     Open DataFile For Input As #1
  95.     For I = 1 To 100
  96.     If EOF(1) Then N = I - 1: Exit For
  97.     Input #1, Surname
  98.     If EOF(1) Then N = I - 1: Exit For
  99.     ' .. in case there was a blank line
  100.     Input #1, Address
  101.     Surnames(I) = Surname
  102.     Addresses(I) = Address
  103.     Next I
  104.     Close #1
  105.     ' Dump the arrays to the Debug window
  106.     Debug.Print
  107.     Debug.Print "Array ..."
  108.     For I = 1 To N
  109.     Debug.Print Surnames(I), Addresses(I)
  110.     Next I
  111. End Sub
  112. Sub TryAssoc ()
  113.     Dim DataFile As String
  114.     Dim Surname As String, Address As String
  115.     Const ASSOC_ENUMERATE = 0
  116.     ' Set the full path for the data file
  117.     If Right$(App.Path, 1) = "\" Then
  118.     DataFile = App.Path & "ADDR.DAT"
  119.     Else
  120.     DataFile = App.Path & "\" & "ADDR.DAT"
  121.     End If
  122.     ' Read in the names and addresses
  123.     Open DataFile For Input As #1
  124.     Do Until EOF(1)
  125.     Input #1, Surname
  126.     If EOF(1) Then Exit Do
  127.     ' .. in case there was a blank line
  128.     Input #1, Address
  129.     Addrs.Key = Surname
  130.     Addrs.Value = Address
  131.     Loop
  132.     Close #1
  133.     ' Dump the arrays to the Debug window
  134.     Debug.Print
  135.     Debug.Print "Assoc ..."
  136.     Addrs.Key = ""
  137.     Do
  138.     Addrs.Key = Addrs.NextKey
  139.     If Addrs.Key = "" Then Exit Do
  140.     Debug.Print Addrs.Key, Addrs.Value
  141.     Loop
  142.     ' Now dump them again using the Enumerate event
  143.     Debug.Print
  144.     Debug.Print "Assoc using Enumerate ..."
  145.     Addrs.Action=ASSOC_ENUMERATE
  146. End Sub
  147.