Click to See Complete Forum and Search --> : Search DAT file


coe6
November 29th, 2000, 06:01 PM
I have a DAT file (C:Zipcodes\SortedZi.dat)which contains zip codes, cities, and states in common seperated format.
For example: "45440","Dayton","OH"
On a form, I have a 3 text boxes:
txt.Zip, txt.City, and txt.State,
which I would like to use to display the output of this file, and a command button cmdSearch.
I want the user to enter a zip code in txt.Zip and when the Search button is pressed, the corresponding City and State appears in the textboxes. I am trying to read the file into an array of UDT and use a sequential search, but am not having any luck. Can anyone help?

d.paulson
November 29th, 2000, 06:49 PM
option Explicit
Dim arraynum as Integer
Dim zip() as string
Dim city() as string
Dim state() as string

private Sub form_load()
'load file into array
Dim ffile as Integer
ffile = FreeFile
Open "C:Zipcodes\SortedZi.dat" for input as #ffile
While Not EOF(ffile)
arraynum = arraynum + 1
ReDim Preserve zip(arraynum)
ReDim Preserve city(arraynum)
ReDim Preserve state(arraynum)
input #ffile, zip(arraynum), city(arraynum), state(arraynum)
Wend
Close #ffile
End Sub

private Sub cmdSearch_Click()
Dim search as Integer
for search = 1 to arraynum
If zip(search) = Trim(txtzip) then
txtcity = city(search)
txtstate = state(search)
Exit Sub
End If
next
MsgBox "Zip not found"
End Sub






David Paulson