CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: Search DAT file

  1. #1
    Join Date
    Nov 2000
    Posts
    13

    Search DAT file

    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?


  2. #2
    Join Date
    Jan 2000
    Location
    Saskatchewan, Canada
    Posts
    595

    Re: Search DAT file


    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured