|
-
Mar 10th, 2009, 07:12 PM
#1
Thread Starter
New Member
VB5 String
Hi I have a test box where the user enters an address. I would like to know how to parse that string and display it.
Ex. User Inputs: 22 Blah Street West
Output:
Street Number: 22
Street Name: Blah
Street Type: Street
Street Direction: West
I know its something to do wth the Substring but I can't seem to figure it out how to seperate the string into these categories.
Thanks for your help.
-
Mar 10th, 2009, 07:29 PM
#2
Re: VB5 String
That's quite an ordeal you are asking about considering the umpteen-hundred different ways an address can be listed. You will need a table of search arguments and search the address string for each and every one of the arguments.
Typical search arguments might be:
Street
Ave
Way
Drive
Blvd
Str
St
Dr
Circle
North
South
East
West
N
S
E
W
.....not to mention NE, NW, SE, etc
any numeric expression
any fractional expression
numeric addresses affixed with th, st, nd, rd, etc (1st St, 22nd Ave, etc)
etc
etc
...and the list goes on and on....
So, get a list of as many of these as you can possibly think of and put them in a table (like a listbox for example)
For each of the search arguments in your list you will then do something like this:
Code:
'
'
For n = 0 to List1.listCount - 1
'
'
'
q = Instr(AddressString, List1.List(n))
If q > 0 Then
'
' Do something for the search argument in the listbox at index 0 using q as the
' starting position of the found argument in the string
'
End if
'
'
'
Next n
Another approach is to seperate the string by the space and build an array of each word in the string. Then search through the array similar in the same way as illustrated above
Code:
'
'
Dim StreetElements() As String
StringElements = Split(StreetString, " ")
'
'
Now StreetElements contains all non-space words
Last edited by jmsrickland; Mar 10th, 2009 at 07:36 PM.
Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.
-
Mar 10th, 2009, 07:53 PM
#3
Fanatic Member
Re: VB5 String
I have VB5 (cause I'm cheap), and this is a functions that mimics VB6's split. It may not solve the logic problems but it helps you run alot of programs you find in this forum.
copy this into a form and run:
Code:
Private Sub Form_Load()
Dim x As Variant, i As Integer
Me.Show
x = split("22 Blah Street West", " ")
Print "Street Number: " & x(0)
Print "Street Name: " & x(1)
Print "Street Type: " & x(2)
Print "Street Direction: " & x(3)
End Sub
Private Function split(ByVal srch As String, ByVal fnd As String)
Dim Temp() As String, i As Integer, j As Integer, x As Integer
ReDim Temp(0)
Temp(0) = srch
If srch = "" Then
Temp(0) = ""
GoTo splitout
End If
i = 1 'pointer
x = 0 'dimension
Do While InStr(Temp(x), fnd) > 0
ReDim Preserve Temp(x + 1)
Temp(x + 1) = Mid(Temp(x), InStr(Temp(x), fnd) + Len(fnd))
Temp(x) = Left(Temp(x), InStr(Temp(x), fnd) - 1)
x = x + 1
Loop
splitout:
split = Temp
End Function
the "Split" was introduced with VB6
Last edited by technorobbo; Mar 10th, 2009 at 08:29 PM.
-
Mar 10th, 2009, 08:18 PM
#4
Re: VB5 String
Code:
Dim MyAddress As String, MySubstr() As String
MyAddress = "22 Blah Street West"
MySubstr() = Split(MyAddress, " ")
For I = 0 To UBound(MySubstr())
MsgBox MySubstr(I)
Next
-
Mar 10th, 2009, 10:40 PM
#5
Re: VB5 String
 Originally Posted by Code Doc
Code:
Dim MyAddress As String, MySubstr() As String
MyAddress = "22 Blah Street West"
MySubstr() = Split(MyAddress, " ")
For I = 0 To UBound(MySubstr())
MsgBox MySubstr(I)
Next
Same as post #2 and #3 except I didn't show the loop. Anyway, he is using VB5. However, this one and the one in post #3 are not really what he needs. You guys are just showing what is in the array but not really isolating each element out of the address string and being able to distinguish one element from another. What is in this that shows Street, Direction, Number, or Type for example if the address string was different from the example you used
Last edited by jmsrickland; Mar 10th, 2009 at 10:50 PM.
Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.
-
Mar 10th, 2009, 11:02 PM
#6
Hyperactive Member
Re: VB5 String
You could always use an INet control (msinet.ocx) to load up www.mapquest.com to format it... lol.
Although it may be dropping a nuke to kill a cockroach.
-
Mar 10th, 2009, 11:30 PM
#7
Re: VB5 String
You could always use an INet control (msinet.ocx) to load up www.mapquest.com to format it
How would you go about doing that?
Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.
-
Mar 12th, 2009, 11:30 PM
#8
Hyperactive Member
Re: VB5 String
 Originally Posted by jmsrickland
You could always use an INet control (msinet.ocx) to load up www.mapquest.com to format it
How would you go about doing that?
"www.mapquest.com/maps?city=West+Hollywood&state=CA&address=700+San+Vicente&country=US&geocode=ADDRESS"
This is the format that mapquest uses to poll map lookups (and the fan mail address of Christian Bale ). Format with the user data. Use the Inet control to download the HTML of the new page and scan through the code down to the address (instr the street number) to see what it changed to.
Below are some subroutines that allow you to get your computer's external IP address by using Inet control to access a webpage like "showip.net" and scanning through the HTML to find the IP, as an example of what I mean:
vb Code:
Private myIPAddress As String Public Function ExternalIP() As String Static isActive As Boolean Dim strHTML As String Dim curUrl As Integer Dim myUrl(1 To 4) As String Dim N As Integer Do While isActive DoEvents Loop If myIPAddress <> "" Then ExternalIP = myIPAddress Exit Function End If isActive = True myUrl(1) = "http://www.mediacollege.com/internet/utilities/show-ip.shtml" myUrl(2) = "http://www.lawrencegoetz.com/programs/ipinfo/" myUrl(3) = "http://ip-adress.com/" myUrl(4) = "http://showip.net/" For curUrl = 1 To 4 If frmMain.netMain.StillExecuting Then frmMain.netMain.Cancel 'Cancel inet if it's still doing something. strHTML = frmMain.netMain.OpenURL(myUrl(curUrl)) 'Get the HTML source code to the webpage. If Len(strHTML) > 0 Then 'Check if the server returned any data. myIPAddress = GetIP(strHTML) If Len(myIPAddress) > 0 Then ExternalIP = myIPAddress isActive = False Exit Function End If End If Next curUrl myIPAddress = frmMain.sckCon(0).LocalIP ExternalIP = myIPAddress isActive = False End Function Private Function GetIP(HTML As String) As String Dim lastPos As Integer Dim curPos As Integer Dim curStr As String Dim offset As Integer curPos = InStr(2000, HTML, ".") Do While curPos > 0 curStr = Mid$(HTML, curPos, 1) offset = -1 Do While IsIPChar(Mid$(HTML, curPos + offset, 1)) curStr = Mid$(HTML, curPos + offset, 1) & curStr offset = offset - 1 Loop offset = 1 Do While IsIPChar(Mid$(HTML, curPos + offset, 1)) curStr = curStr & Mid$(HTML, curPos + offset, 1) offset = offset + 1 Loop If ChkIP(curStr) Then GetIP = curStr Exit Function End If lastPos = curPos curPos = InStr(lastPos + 1, HTML, ".") Loop End Function Private Function ChkIP(IP As String) As Boolean Dim LastPer As Integer Dim N As Integer If Len(IP) > 15 Or Len(IP) < 7 Or CountPeriods(IP) <> 3 Then ChkIP = False Exit Function End If For N = 1 To Len(IP) If Mid$(IP, N, 1) = "." Then LastPer = N ElseIf N - LastPer > 3 Or Not IsNum(Mid$(IP, N, 1)) Then ChkIP = Fals Exit Function End If Next N ChkIP = True End Function Private Function CountPeriods(chkStr As String) As Integer Dim Total As Integer Dim N As Integer For N = 1 To Len(chkStr) If Mid$(chkStr, N, 1) = "." Then Total = Total + 1 Next N CountPeriods = Total End Function Private Function IsIPChar(curChar As String) As Boolean IsIPChar = IIf(IsNum(curChar) Or curChar = ".", True, False) End Function Private Function IsNum(Char As String) As Boolean Select Case Char Case "0": IsNum = True Case "1": IsNum = True Case "2": IsNum = True Case "3": IsNum = True Case "4": IsNum = True Case "5": IsNum = True Case "6": IsNum = True Case "7": IsNum = True Case "8": IsNum = True Case "9": IsNum = True Case Else: IsNum = False End Select End Function
Last edited by deathfxu; May 26th, 2009 at 02:15 PM.
Reason: clarification
-
Mar 12th, 2009, 11:36 PM
#9
Hyperactive Member
Re: VB5 String
Just to reemphasize, this is clearly over-coding for OP. Malik17th, i'm not actually suggesting you do this, i'm just responding to Jmsrickland.
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
|