Results 1 to 9 of 9

Thread: VB5 String

Threaded View

  1. #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

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