Solved

Address problem

Posted on 2004-09-08
8
228 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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
 
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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Windows 10 start screen issues 9 61
How to Add / Edit Windows Menu 4 73
how to know if my Checkbox is True in VB6.0? 9 65
MS SQL Update query with connected table data 3 59
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

685 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