Solved

Address problem

Posted on 2004-09-08
8
224 Views
Last Modified: 2008-02-01
I need to split up the address data.
so
12345  mystreet  
or
123 mystreet
 
they are in one field in the database  and not broken up i need to grab the number  so I'm thinking if there is some way to go to the first space of 123 mystreet. not sure how to code this to pull just the street number.
Thanks for any help
0
Comment
Question by:cdb424ttm
8 Comments
 
LVL 18

Expert Comment

by:JR2003
ID: 12007004
Val("12345  mystreet ")
will give the number 12345

JR
0
 
LVL 6

Accepted Solution

by:
bkthompson2112 earned 500 total points
ID: 12007037
Hi cdb424ttm,

Try this:

Dim AddrParts() as string
AddrParts = Split("12345 mystreet", " ")

AddrParts(0) will contain "12345"
AddrParts(1) will contain "mystreet"

bkt
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 12007073
Split may not be such a good idea since if you have "12345 E Highland Drive" you will end up with "E", "Highland" and "Drive" all in seperate elements of the array.

Private Sub Command1_Click()
    Dim address As String
    Dim firstSpace As Integer
    Dim number As String
    Dim street As String
   
    address = "12345  mystreet"
    firstSpace = InStr(address, " ")
    number = Trim(Left(address, firstSpace))
    street = Trim(Mid(address, firstSpace))
End Sub
0
 
LVL 6

Expert Comment

by:bkthompson2112
ID: 12007316
>Split may not be such a good idea

That's true.  It will depend on the data and how it's used.

Another example:

"12345 1/2 E Highland Drive"
number = 123456
street = 1/2 E Highland Drive

The point is, neither solution is perfect.  It will depend on the data format and how the program intends to use it.
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 76

Expert Comment

by:GrahamSkan
ID: 12007325

Perhaps you should look for a comma first, I used to work at "Computer House, Boston Manor Road", If missing, go for the first space.

v = Split(Address, ",")
If UBound(v) = 0 Then
    v = Split(Address, " ")
End If
building = v(0)
street = v(1)
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 12007344
Good point bkthompson2112.

Idle_Mind
0
 
LVL 19

Expert Comment

by:Shauli
ID: 12007509
cdb424ttm ,

I did not participate in this paq, however, I think you have selected the wrong answer.
Lets see:
JR's solution will fail if the address is "12345 72nd Street" because it will result in 1234572
bkthompson2112's (accepted answer) will fail because the result would be AddrParts(0) will contain "12345" AND AddrParts(0) will contain "72nd", so what about the rest of the address?

Idle_Mind's solution is the right solution, even if in rare cases of "12345 1/2 E Highland Drive" it does not give a solution.

You realize that the solution you have chosen will result, in this case, like this:
AddrParts(0) will contain "12345"
AddrParts(1) will contain "1/2"

Just to let you know :)

And my appology for interupting,

S
0
 
LVL 6

Expert Comment

by:bkthompson2112
ID: 12007581
Shauli,  you're exactly right.  As I pointed out, none of the proposed solutions is perfect.

I've always found address parsing to be problematic.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now