Results 1 to 5 of 5

Thread: Read From URL[Resolved]

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    May 2004
    Posts
    566

    Arrow Read From URL[Resolved]

    Code:
    Const sURL = "http://www.website.com/ip.htm"
    
        Dim hOpen As Long, hFile As Long, sBuffer As String, Ret As Long
        'Create a buffer for the file we're going to download
        sBuffer = Space(1000)
        'Create an internet connection
        hOpen = InternetOpen(scUserAgent, INTERNET_OPEN_TYPE_DIRECT, vbNullString, vbNullString, 0)
        'Open the url
        hFile = InternetOpenUrl(hOpen, sURL, vbNullString, ByVal 0&, INTERNET_FLAG_RELOAD, ByVal 0&)
        'Read the first 1000 bytes of the file
        InternetReadFile hFile, sBuffer, 1000, Ret
        'clean up
        InternetCloseHandle hFile
        InternetCloseHandle hOpen
        'Show our file
        MsgBox sBuffer
    what my intentions are is reading the url file for ip's and if the ip is in the file i want a messagebox to appear saying so. but, i dont know how to go about it.

    to get the ip i just:
    Code:
    Winsock1.LocalIP = MyIP
    'etc..
    and in the 1st above code i want this in it(which is way off i know):
    Code:
    If MyIP = in sURL Then
    MsgBox "blah blah"
    but i dont know how to integrate it...

    help
    Last edited by emyztik; Sep 12th, 2004 at 05:48 PM.

  2. #2
    Fanatic Member TheVader's Avatar
    Join Date
    Oct 2002
    Location
    Rotterdam, the Netherlands
    Posts
    871
    You can use the InStr function to check if the IP is somewhere inside the string.
    VB Code:
    1. If InStr(1, sBuffer, MyIP, vbTextCompare) <> 0 Then
    2.         MsgBox MyIP & " found."
    3.     Else
    4.         MsgBox MyIP & " not found."
    5.     End If
    Author for Visual Basic Web Magazine

    My articles on the Web Browser Control:
    Using the Web Browser Control & Using the DHTML Document Object Model

    The examples referenced in the articles can be found here:

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    May 2004
    Posts
    566
    it doesnt seem to work. what i want it to do is if the persons IP is listed in the URL file i want an msgbox to appear saying so and if it's not, then i just want the program to continue what it was doing. but the code you specified tells me my IP is in the URL file when it's not and tells me it isn't in it when it is. i can't seem to get it to work

  4. #4
    Fanatic Member TheVader's Avatar
    Join Date
    Oct 2002
    Location
    Rotterdam, the Netherlands
    Posts
    871
    Strange, it worked for me... :S The InStr function works quite easy; you pass the string to be searched in as a parameter (the file), and the string to be searched for (the IP). It returns the position in the first string where the second string is found; if it's not found it returns zero. Hence the logic behind my code.

    Can you perhaps post the code you have so far (including API declarations etc.)? And can you put the correct URL in the variable?
    Author for Visual Basic Web Magazine

    My articles on the Web Browser Control:
    Using the Web Browser Control & Using the DHTML Document Object Model

    The examples referenced in the articles can be found here:

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    May 2004
    Posts
    566
    Edit: figured it out.

    thanks guys!
    Last edited by emyztik; Sep 12th, 2004 at 05:47 PM.

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