|
-
May 5th, 2013, 03:43 AM
#2
Re: Please HELP I have aged in a week trying to figure this out have no slept in 36 h
Hi,
From what I can see of your code you are definitely making things more difficult than they need to be.
The first thing to do is read your Zip file into memory so that you save time by NOT reading your file all the time. The next thing to do is then search that loaded object for the Line of Data that starts with the actual Zip code that you are typing. Only then do you split that Data Line and display it in your other TextBox's.
In this example I have sourced a US Zip Code Database from the net if the form of:-
501,Holtsville,NY
544,Holtsville,NY
601,Adjuntas,PR
etc
etc...
Using the above structure, have a go with this:-
Code:
Public Class Form1
Private myZipCodes() As String = IO.File.ReadAllLines(Application.StartupPath & "\USZipCodeDatabase.txt")
Private Sub TextBox1_TextChanged(sender As System.Object, e As System.EventArgs) Handles TextBox1.TextChanged
Dim myZipRecord As String = myZipCodes.Where(Function(x) x.StartsWith(TextBox1.Text & ",")).FirstOrDefault
If Not myZipRecord = String.Empty Then
Dim myZipDetails() As String = myZipRecord.Split(","c)
TextBox2.Text = myZipDetails(1)
TextBox3.Text = myZipDetails(2)
Else
TextBox2.Clear()
TextBox3.Clear()
End If
End Sub
End Class
Hope that helps.
Cheers,
Ian
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|