home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Programming Tool Box
/
SIMS_2.iso
/
tool
/
various
/
assoc
/
example.txt
< prev
next >
Wrap
Text File
|
1995-02-26
|
2KB
|
98 lines
Option Explicit
Dim Surnames(1 To 100) As String, Addresses(1 To 100) As String
Sub Addrs_Enumerate (Key As String, Value As String)
Debug.Print Key, Value
End Sub
Sub btnArray_Click ()
Call TryArray
End Sub
Sub btnAssoc_Click ()
Call TryAssoc
End Sub
Sub btnExit_Click ()
Unload frmMain
End Sub
Sub TryArray ()
Dim DataFile As String
Dim Surname As String, Address As String
Dim I As Integer, N As Integer
' Set the full path for the data file
If Right$(App.Path, 1) = "\" Then
DataFile = App.Path & "ADDR.DAT"
Else
DataFile = App.Path & "\" & "ADDR.DAT"
End If
' Read in the names and addresses
Open DataFile For Input As #1
For I = 1 To 100
If EOF(1) Then N = I - 1: Exit For
Input #1, Surname
If EOF(1) Then N = I - 1: Exit For
' .. in case there was a blank line
Input #1, Address
Surnames(I) = Surname
Addresses(I) = Address
Next I
Close #1
' Dump the arrays to the Debug window
Debug.Print
Debug.Print "Array ..."
For I = 1 To N
Debug.Print Surnames(I), Addresses(I)
Next I
End Sub
Sub TryAssoc ()
Dim DataFile As String
Dim Surname As String, Address As String
Const ASSOC_ENUMERATE = 0
' Set the full path for the data file
If Right$(App.Path, 1) = "\" Then
DataFile = App.Path & "ADDR.DAT"
Else
DataFile = App.Path & "\" & "ADDR.DAT"
End If
' Read in the names and addresses
Open DataFile For Input As #1
Do Until EOF(1)
Input #1, Surname
If EOF(1) Then Exit Do
' .. in case there was a blank line
Input #1, Address
Addrs.Key = Surname
Addrs.Value = Address
Loop
Close #1
' Dump the arrays to the Debug window
Debug.Print
Debug.Print "Assoc ..."
Addrs.Key = ""
Do
Addrs.Key = Addrs.NextKey
If Addrs.Key = "" Then Exit Do
Debug.Print Addrs.Key, Addrs.Value
Loop
' Now dump them again using the Enumerate event
Debug.Print
Debug.Print "Assoc using Enumerate ..."
Addrs.Action = ASSOC_ENUMERATE
End Sub