Results 1 to 9 of 9

Thread: VB5 String

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2009
    Posts
    3

    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.

  2. #2
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    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.

  3. #3
    Fanatic Member technorobbo's Avatar
    Join Date
    Dec 2008
    Location
    Chicago
    Posts
    864

    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.
    Have Fun,

    TR
    _____________________________
    Check out my Alpha DogFighter2D Game Demo and Source code. Direct Download:http://home.comcast.net/~technorobbo/Alpha.zip or Read about it in the forum:http://www.vbforums.com/showthread.php?t=551700. Now in 3D!!! http://home.comcast.net/~technorobbo/AlPha3D.zip or read about it in the forum: http://www.vbforums.com/showthread.php?goto=newpost&t=552560 and IChessChat3D internet chess game

  4. #4
    PowerPoster Code Doc's Avatar
    Join Date
    Mar 2007
    Location
    Omaha, Nebraska
    Posts
    2,354

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

  5. #5
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: VB5 String

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

  6. #6
    Hyperactive Member deathfxu's Avatar
    Join Date
    Mar 2009
    Location
    USA
    Posts
    279

    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.

  7. #7
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    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.

  8. #8
    Hyperactive Member deathfxu's Avatar
    Join Date
    Mar 2009
    Location
    USA
    Posts
    279

    Re: VB5 String

    Quote 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:
    1. Private myIPAddress As String
    2.  
    3. Public Function ExternalIP() As String
    4. Static isActive As Boolean
    5. Dim strHTML As String
    6. Dim curUrl As Integer
    7. Dim myUrl(1 To 4) As String
    8. Dim N As Integer
    9.  
    10. Do While isActive
    11.     DoEvents
    12. Loop
    13.  
    14. If myIPAddress <> "" Then
    15.     ExternalIP = myIPAddress
    16.     Exit Function
    17. End If
    18.  
    19. isActive = True
    20.  
    21. myUrl(1) = "http://www.mediacollege.com/internet/utilities/show-ip.shtml"
    22. myUrl(2) = "http://www.lawrencegoetz.com/programs/ipinfo/"
    23. myUrl(3) = "http://ip-adress.com/"
    24. myUrl(4) = "http://showip.net/"
    25.  
    26. For curUrl = 1 To 4
    27.     If frmMain.netMain.StillExecuting Then frmMain.netMain.Cancel 'Cancel inet if it's still doing something.
    28.     strHTML = frmMain.netMain.OpenURL(myUrl(curUrl)) 'Get the HTML source code to the webpage.
    29.     If Len(strHTML) > 0 Then 'Check if the server returned any data.
    30.         myIPAddress = GetIP(strHTML)
    31.         If Len(myIPAddress) > 0 Then
    32.             ExternalIP = myIPAddress
    33.             isActive = False
    34.             Exit Function
    35.         End If
    36.     End If
    37. Next curUrl
    38. myIPAddress = frmMain.sckCon(0).LocalIP
    39. ExternalIP = myIPAddress
    40. isActive = False
    41.  
    42. End Function
    43.  
    44. Private Function GetIP(HTML As String) As String
    45. Dim lastPos As Integer
    46. Dim curPos As Integer
    47. Dim curStr As String
    48. Dim offset As Integer
    49.  
    50. curPos = InStr(2000, HTML, ".")
    51. Do While curPos > 0
    52.  
    53.     curStr = Mid$(HTML, curPos, 1)
    54.  
    55.     offset = -1
    56.     Do While IsIPChar(Mid$(HTML, curPos + offset, 1))
    57.         curStr = Mid$(HTML, curPos + offset, 1) & curStr
    58.         offset = offset - 1
    59.     Loop
    60.  
    61.     offset = 1
    62.     Do While IsIPChar(Mid$(HTML, curPos + offset, 1))
    63.         curStr = curStr & Mid$(HTML, curPos + offset, 1)
    64.         offset = offset + 1
    65.     Loop
    66.  
    67.     If ChkIP(curStr) Then
    68.         GetIP = curStr
    69.         Exit Function
    70.     End If
    71.  
    72.     lastPos = curPos
    73.     curPos = InStr(lastPos + 1, HTML, ".")
    74.  
    75. Loop
    76.  
    77. End Function
    78.  
    79. Private Function ChkIP(IP As String) As Boolean
    80. Dim LastPer As Integer
    81. Dim N As Integer
    82.  
    83. If Len(IP) > 15 Or Len(IP) < 7 Or CountPeriods(IP) <> 3 Then
    84.     ChkIP = False
    85.     Exit Function
    86. End If
    87. For N = 1 To Len(IP)
    88.     If Mid$(IP, N, 1) = "." Then
    89.         LastPer = N
    90.     ElseIf N - LastPer > 3 Or Not IsNum(Mid$(IP, N, 1)) Then
    91.         ChkIP = Fals
    92.         Exit Function
    93.     End If
    94. Next N
    95. ChkIP = True
    96.  
    97. End Function
    98.  
    99. Private Function CountPeriods(chkStr As String) As Integer
    100. Dim Total As Integer
    101. Dim N As Integer
    102.  
    103. For N = 1 To Len(chkStr)
    104.     If Mid$(chkStr, N, 1) = "." Then Total = Total + 1
    105. Next N
    106. CountPeriods = Total
    107.  
    108. End Function
    109.  
    110. Private Function IsIPChar(curChar As String) As Boolean
    111.       IsIPChar = IIf(IsNum(curChar) Or curChar = ".", True, False)
    112. End Function
    113.  
    114. Private Function IsNum(Char As String) As Boolean
    115.  
    116. Select Case Char
    117. Case "0": IsNum = True
    118. Case "1": IsNum = True
    119. Case "2": IsNum = True
    120. Case "3": IsNum = True
    121. Case "4": IsNum = True
    122. Case "5": IsNum = True
    123. Case "6": IsNum = True
    124. Case "7": IsNum = True
    125. Case "8": IsNum = True
    126. Case "9": IsNum = True
    127. Case Else: IsNum = False
    128. End Select
    129.  
    130. End Function
    Last edited by deathfxu; May 26th, 2009 at 02:15 PM. Reason: clarification

  9. #9
    Hyperactive Member deathfxu's Avatar
    Join Date
    Mar 2009
    Location
    USA
    Posts
    279

    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
  •  



Click Here to Expand Forum to Full Width