Results 1 to 32 of 32

Thread: [Resolved with inet control]internetreadfile

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Feb 2006
    Location
    Hyderabad, India
    Posts
    233

    [Resolved with inet control]internetreadfile

    Hello,
    I am using internetreadfile api to download the code of a webpage. I have set the buffer size to 1024. I am writing the each downloaded line to a textfile. Problem is the result is not the same for all executions of the program. Some times it is working fine. Sometimes, some additional characters are being added. Some times a part of the line is being printed to the file more than once. Is this expected or am I doing something wrong here?
    Thank you.
    Last edited by srisa; May 25th, 2006 at 10:00 AM. Reason: marking the thread resolved

  2. #2
    Hyperactive Member kazar's Avatar
    Join Date
    Apr 2006
    Location
    UK
    Posts
    323

    Re: internetreadfile

    Is there a reason why you aren't using the Inet Control? It's a lot more reliable.
    KAZAR

    The Law Of Programming:

    As the Number of Lines of code increases, the number of bugs generated by fixing a bug increases exponentially.
    __________________________________
    www.startingqbasic.co.uk

  3. #3
    Fanatic Member
    Join Date
    Aug 2005
    Location
    South Africa
    Posts
    760

    Re: internetreadfile

    Maybe srisa doesn't want to use a control.
    I personally like the Inet control although it isn't always reliable
    If I helped you out, please consider adding to my reputation!

    -- "The faulty interface lies between the chair and the keyboard" --

    VB6 Programs By Me:
    ** Dictionary, Thesaurus & Rhyme-Generator In One ** WMP Recent Files List Editor ** Pretty Impressive Clock ** Extract Firefox History **

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Feb 2006
    Location
    Hyderabad, India
    Posts
    233

    Re: internetreadfile

    If I am designing the application for windows : If windows is the OS being used , we can expect Internet Explorer to be used. When IE is used wininet.dll will be present on the user's system. If the application is downloaded from net, using api's will reduce the size of the application.
    Sounds pretty hi-fi.
    Well, real answer is I am learning VB. As part of it I am trying to use api's. Internetreadfile makes the entry here.

  5. #5
    Fanatic Member
    Join Date
    Aug 2005
    Location
    South Africa
    Posts
    760

    Re: internetreadfile

    That's a good enough reason.
    Unfortunately I have no experience with this API so I can't help, sorry.
    If I helped you out, please consider adding to my reputation!

    -- "The faulty interface lies between the chair and the keyboard" --

    VB6 Programs By Me:
    ** Dictionary, Thesaurus & Rhyme-Generator In One ** WMP Recent Files List Editor ** Pretty Impressive Clock ** Extract Firefox History **

  6. #6
    Hyperactive Member kazar's Avatar
    Join Date
    Apr 2006
    Location
    UK
    Posts
    323

    Re: internetreadfile

    The function below should download the entire file to a file of your choice, not matter what the buffer size you choose.



    VB Code:
    1. Option Explicit
    2. Const INTERNET_OPEN_TYPE_DIRECT = 1
    3. Const INTERNET_OPEN_TYPE_PROXY = 3
    4. Const INTERNET_FLAG_RELOAD = &H80000000
    5.  
    6. Private Declare Function InternetOpen Lib "wininet" Alias "InternetOpenA" (ByVal sAgent As String, ByVal lAccessType As Long, ByVal sProxyName As String, ByVal sProxyBypass As String, ByVal lFlags As Long) As Long
    7. Private Declare Function InternetCloseHandle Lib "wininet" (ByVal hInet As Long) As Integer
    8. Private Declare Function InternetReadFile Lib "wininet" (ByVal hFile As Long, ByVal sBuffer As String, ByVal lNumBytesToRead As Long, lNumberOfBytesRead As Long) As Integer
    9. Private Declare Function InternetOpenUrl Lib "wininet" Alias "InternetOpenUrlA" (ByVal hInternetSession As Long, ByVal lpszUrl As String, ByVal lpszHeaders As String, ByVal dwHeadersLength As Long, ByVal dwFlags As Long, ByVal dwContext As Long) As Long
    10. Private Sub GetFile(sourcefile As String, destfile As String, buffersize As Long)
    11.  
    12.  
    13.     Dim hOpen As Long, hFile As Long, sBuffer As String, Ret As Long, oldbuffer As String
    14.     'Create a buffer for the file we're going to download
    15.     sBuffer = Space(buffersize)
    16.     'Create an internet connection
    17.     hOpen = InternetOpen(App.EXEName, INTERNET_OPEN_TYPE_DIRECT, vbNullString, vbNullString, 0)
    18.     'Open the url
    19.     hFile = InternetOpenUrl(hOpen, sourcefile, vbNullString, ByVal 0&, INTERNET_FLAG_RELOAD, ByVal 0&)
    20.     Open destfile For Output As #1
    21.    
    22.     Do
    23.     oldbuffer = sBuffer
    24.     InternetReadFile hFile, sBuffer, buffersize, Ret
    25.     If sBuffer = oldbuffer Then GoTo cleanup
    26.     Print #1, sBuffer
    27.    
    28.     Loop
    29.    
    30. cleanup:
    31.     InternetCloseHandle hFile
    32.     InternetCloseHandle hOpen
    33.     Close
    34. End Sub

    Hope that works, ask if you have any queries
    KAZAR

    The Law Of Programming:

    As the Number of Lines of code increases, the number of bugs generated by fixing a bug increases exponentially.
    __________________________________
    www.startingqbasic.co.uk

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Feb 2006
    Location
    Hyderabad, India
    Posts
    233

    Re: internetreadfile

    Thank you.The function as such is working fine. But , how do I check for errors during download like connection timeout, network disconnection or such things. During one of the trial runs, session got timed out, result being incomplete file download.

  8. #8
    Hyperactive Member kazar's Avatar
    Join Date
    Apr 2006
    Location
    UK
    Posts
    323

    Re: internetreadfile

    Erm...You could use the checkinternetconnection function. I'll check when i get back home, and post the fix.
    KAZAR

    The Law Of Programming:

    As the Number of Lines of code increases, the number of bugs generated by fixing a bug increases exponentially.
    __________________________________
    www.startingqbasic.co.uk

  9. #9
    Hyperactive Member kazar's Avatar
    Join Date
    Apr 2006
    Location
    UK
    Posts
    323

    Re: internetreadfile

    VB Code:
    1. Option Explicit
    2. Const INTERNET_OPEN_TYPE_DIRECT = 1
    3. Const INTERNET_OPEN_TYPE_PROXY = 3
    4. Const INTERNET_FLAG_RELOAD = &H80000000
    5. Private Const FLAG_ICC_FORCE_CONNECTION = &H1
    6. Private Declare Function InternetCheckConnection Lib "wininet.dll" Alias "InternetCheckConnectionA" (ByVal lpszUrl As String, ByVal dwFlags As Long, ByVal dwReserved As Long) As Long
    7.  
    8. Private Declare Function InternetOpen Lib "wininet" Alias "InternetOpenA" (ByVal sAgent As String, ByVal lAccessType As Long, ByVal sProxyName As String, ByVal sProxyBypass As String, ByVal lFlags As Long) As Long
    9. Private Declare Function InternetCloseHandle Lib "wininet" (ByVal hInet As Long) As Integer
    10. Private Declare Function InternetReadFile Lib "wininet" (ByVal hFile As Long, ByVal sBuffer As String, ByVal lNumBytesToRead As Long, lNumberOfBytesRead As Long) As Integer
    11. Private Declare Function InternetOpenUrl Lib "wininet" Alias "InternetOpenUrlA" (ByVal hInternetSession As Long, ByVal lpszUrl As String, ByVal lpszHeaders As String, ByVal dwHeadersLength As Long, ByVal dwFlags As Long, ByVal dwContext As Long) As Long
    12. Private Sub GetFile(sourcefile As String, destfile As String, buffersize As Long)
    13.  
    14.  
    15.     Dim hOpen As Long, hFile As Long, sBuffer As String, Ret As Long, oldbuffer As String
    16.     'Create a buffer for the file we're going to download
    17.     sBuffer = Space(buffersize)
    18.     'Create an internet connection
    19.     hOpen = InternetOpen(App.EXEName, INTERNET_OPEN_TYPE_DIRECT, vbNullString, vbNullString, 0)
    20.     'Open the url
    21.     hFile = InternetOpenUrl(hOpen, sourcefile, vbNullString, ByVal 0&, INTERNET_FLAG_RELOAD, ByVal 0&)
    22.     Open destfile For Output As #1
    23.    
    24.     Do
    25.          If InternetCheckConnection(sourcefile, FLAG_ICC_FORCE_CONNECTION, 0) = False Then
    26.                Do Until InternetCheckConnection(sourcefile, FLAG_ICC_FORCE_CONNECTION, 0) = True
    27.                Loop
    28.          End If
    29.     oldbuffer = sBuffer
    30.     InternetReadFile hFile, sBuffer, buffersize, Ret
    31.     If sBuffer = oldbuffer Then GoTo cleanup
    32.     Print #1, sBuffer
    33.    
    34.     Loop
    35.    
    36. cleanup:
    37.     InternetCloseHandle hFile
    38.     InternetCloseHandle hOpen
    39.     Close
    40. End Sub

    Right then, that should, if it can't connect to the desired page, for whatever reason, it will hang until it can. Then it will continue download.

    Hope thats what you're looking for.
    KAZAR

    The Law Of Programming:

    As the Number of Lines of code increases, the number of bugs generated by fixing a bug increases exponentially.
    __________________________________
    www.startingqbasic.co.uk

  10. #10
    Fanatic Member
    Join Date
    Aug 2005
    Location
    South Africa
    Posts
    760

    Re: internetreadfile

    You should use DoEvents within it and add a timeout incase the user isn't connected to the net
    If I helped you out, please consider adding to my reputation!

    -- "The faulty interface lies between the chair and the keyboard" --

    VB6 Programs By Me:
    ** Dictionary, Thesaurus & Rhyme-Generator In One ** WMP Recent Files List Editor ** Pretty Impressive Clock ** Extract Firefox History **

  11. #11
    Hyperactive Member kazar's Avatar
    Join Date
    Apr 2006
    Location
    UK
    Posts
    323

    Re: internetreadfile

    First off, it's only rough code _

    Secondly, he's right, so here you go -

    VB Code:
    1. Option Explicit
    2. Const INTERNET_OPEN_TYPE_DIRECT = 1
    3. Const INTERNET_OPEN_TYPE_PROXY = 3
    4. Const INTERNET_FLAG_RELOAD = &H80000000
    5. Private Const FLAG_ICC_FORCE_CONNECTION = &H1
    6. Private Declare Function InternetCheckConnection Lib "wininet.dll" Alias "InternetCheckConnectionA" (ByVal lpszUrl As String, ByVal dwFlags As Long, ByVal dwReserved As Long) As Long
    7.  
    8. Private Declare Function InternetOpen Lib "wininet" Alias "InternetOpenA" (ByVal sAgent As String, ByVal lAccessType As Long, ByVal sProxyName As String, ByVal sProxyBypass As String, ByVal lFlags As Long) As Long
    9. Private Declare Function InternetCloseHandle Lib "wininet" (ByVal hInet As Long) As Integer
    10. Private Declare Function InternetReadFile Lib "wininet" (ByVal hFile As Long, ByVal sBuffer As String, ByVal lNumBytesToRead As Long, lNumberOfBytesRead As Long) As Integer
    11. Private Declare Function InternetOpenUrl Lib "wininet" Alias "InternetOpenUrlA" (ByVal hInternetSession As Long, ByVal lpszUrl As String, ByVal lpszHeaders As String, ByVal dwHeadersLength As Long, ByVal dwFlags As Long, ByVal dwContext As Long) As Long
    12. Public timeoutcount as long
    13. Private Sub GetFile(sourcefile As String, destfile As String, buffersize As Long, timeoutlevel as long)
    14.  
    15.  
    16.  
    17.     Dim hOpen As Long, hFile As Long, sBuffer As String, Ret As Long, oldbuffer As String
    18.     'Create a buffer for the file we're going to download
    19.     sBuffer = Space(buffersize)
    20.     'Create an internet connection
    21.     hOpen = InternetOpen(App.EXEName, INTERNET_OPEN_TYPE_DIRECT, vbNullString, vbNullString, 0)
    22.     'Open the url
    23.     hFile = InternetOpenUrl(hOpen, sourcefile, vbNullString, ByVal 0&, INTERNET_FLAG_RELOAD, ByVal 0&)
    24.     Open destfile For Output As #1
    25.    
    26.     Do
    27.          If InternetCheckConnection(sourcefile, FLAG_ICC_FORCE_CONNECTION, 0) = False Then
    28.  
    29. timeoutcount = 0
    30. timeouttimer.enabled = True
    31. timeouttimer.interval = 100
    32.  
    33.                Do Until InternetCheckConnection(sourcefile, FLAG_ICC_FORCE_CONNECTION, 0) = True
    34.                Doevents
    35. If timeoutcount = timeoutlevel then
    36.         msgbox("Connection Timed Out")
    37.         timeouttimer.enabled = False
    38.         Exit Sub
    39. End If
    40.                Loop
    41. timeouttimer.enabled = False
    42.          End If
    43.     oldbuffer = sBuffer
    44.     InternetReadFile hFile, sBuffer, buffersize, Ret
    45.     If sBuffer = oldbuffer Then GoTo cleanup
    46.     Print #1, sBuffer
    47.    
    48.     Loop
    49.    
    50. cleanup:
    51.     InternetCloseHandle hFile
    52.     InternetCloseHandle hOpen
    53.     Close
    54. End Sub
    55.  
    56. Sub timeouttimer_Timer()
    57.  
    58.       timeoutcount = timeoutcount + 1
    59.  
    60. End sub

    That should, if it has to wait a set length of time for a connection, popup a timeout message and exit sub. You have to make a timer and call it timeouttimer, though.
    KAZAR

    The Law Of Programming:

    As the Number of Lines of code increases, the number of bugs generated by fixing a bug increases exponentially.
    __________________________________
    www.startingqbasic.co.uk

  12. #12
    Fanatic Member
    Join Date
    Aug 2005
    Location
    South Africa
    Posts
    760

    Re: internetreadfile

    Looks good [for rough code]
    If I helped you out, please consider adding to my reputation!

    -- "The faulty interface lies between the chair and the keyboard" --

    VB6 Programs By Me:
    ** Dictionary, Thesaurus & Rhyme-Generator In One ** WMP Recent Files List Editor ** Pretty Impressive Clock ** Extract Firefox History **

  13. #13
    Hyperactive Member kazar's Avatar
    Join Date
    Apr 2006
    Location
    UK
    Posts
    323

    Re: internetreadfile

    Hmm, though i still think i prefer inet, at least it always pauses your code until it's done
    KAZAR

    The Law Of Programming:

    As the Number of Lines of code increases, the number of bugs generated by fixing a bug increases exponentially.
    __________________________________
    www.startingqbasic.co.uk

  14. #14

    Thread Starter
    Addicted Member
    Join Date
    Feb 2006
    Location
    Hyderabad, India
    Posts
    233

    Re: internetreadfile

    Well, before using internetopen, I am checking the connection using internetcheckconnection. If connection could be established start downloading , otherwise no. To check if the entire file is downloaded, I am storing the entire file in a string variable and using the instr function to see if </html> tag is present. If it is present then entire file has been downloaded otherwise no. Is this approach ok or am I overlooking or missing something here? And , thanks for the interest. Earlier I have posted three or four times in api section but this is the first time more than one person has taken time to post.

  15. #15
    Hyperactive Member kazar's Avatar
    Join Date
    Apr 2006
    Location
    UK
    Posts
    323

    Re: internetreadfile

    That should do it fine.
    KAZAR

    The Law Of Programming:

    As the Number of Lines of code increases, the number of bugs generated by fixing a bug increases exponentially.
    __________________________________
    www.startingqbasic.co.uk

  16. #16

    Thread Starter
    Addicted Member
    Join Date
    Feb 2006
    Location
    Hyderabad, India
    Posts
    233

    Re: internetreadfile

    Time now for the specifics. I came across a project : at music.yahoo.com site , there will be list of videos alphabetically separated. What he wants is a list of all the videos listed there in this format : artistname | video name | a number. Number : when we hover the mouse over the video name, in the status bar, javascript : playvideo(23457181) , some such number will be displayed. This is the number that is needed. Artist name and videoname are hyperlinks. What I am doing is downloading the entire file and searching for these strings
    search1 = "http://music.yahoo.com/ar-"
    search2 = "javascript : playVideos"
    and trying to retrieve the values. Is this the right approach? If you want I will upload the project that I have written.
    Last edited by srisa; Apr 27th, 2006 at 10:03 AM. Reason: typo

  17. #17
    Hyperactive Member kazar's Avatar
    Join Date
    Apr 2006
    Location
    UK
    Posts
    323

    Re: internetreadfile

    meaning you want to retrieve whatever comes after that value, until...
    KAZAR

    The Law Of Programming:

    As the Number of Lines of code increases, the number of bugs generated by fixing a bug increases exponentially.
    __________________________________
    www.startingqbasic.co.uk

  18. #18

    Thread Starter
    Addicted Member
    Join Date
    Feb 2006
    Location
    Hyderabad, India
    Posts
    233

    Re: internetreadfile

    This is what the a tag for artist looks like , from this the value between the greater than and less than signs ( inner text ) is what I retrieve :
    <a href="http://music.yahoo.com/ar-298276---The-International-Noise-Conspiracy" title="The (International) Noise Conspiracy">The (International) Noise Conspiracy</a>.
    This is what it looks like for javascript thing:
    <a href="javascriptlayVideos(2153097)" class="listheader" title="Reproduction Of Death">Reproduction Of Death</a>
    The value between parantheses gives the number and the value between > and < signs ( inner text again ) gives the album title. I am instr function to retrieve the positions of the symbols and then mid$ function to get the value I want.
    Last edited by srisa; Apr 28th, 2006 at 07:22 AM. Reason: typos again

  19. #19
    Hyperactive Member kazar's Avatar
    Join Date
    Apr 2006
    Location
    UK
    Posts
    323

    Re: internetreadfile

    <a href="http://music.yahoo.com/ar-298276---The-International-Noise-Conspiracy" title="The (International) Noise Conspiracy">The (International) Noise Conspiracy</a>.
    This is what it looks like for javascript thing:
    <a href="javascriptlayVideos(2153097)" class="listheader" title="Reproduction Of Death">Reproduction Of Death</a>

    If the name of album/song is the same for both, are the bold numbers both the same.
    KAZAR

    The Law Of Programming:

    As the Number of Lines of code increases, the number of bugs generated by fixing a bug increases exponentially.
    __________________________________
    www.startingqbasic.co.uk

  20. #20

    Thread Starter
    Addicted Member
    Join Date
    Feb 2006
    Location
    Hyderabad, India
    Posts
    233

    Re: internetreadfile

    The number after ar is the artist number which is being used by the programmer for easy reference to the artist. First value will be the artist name. Value between parantheses is the number, last value will be the title. This string http://music.yahoo.com/ar is common for all the hyperlinks refering to the artists. So I am searching for that text to get the artist's name. The number is parantheses might be some sort of reference to the video in the database or something like that.

  21. #21

    Thread Starter
    Addicted Member
    Join Date
    Feb 2006
    Location
    Hyderabad, India
    Posts
    233

    Re: internetreadfile

    Sorry for going into hibernation for so long. Extracting the string part is ok. But the problem is the downloaded content is not coherent. The code is not in order and some of the lines appear two times etc. I changed the extension of the file to html and opened it in IE. The page was not similar to the page downloaded.There were some errors.
    May be using internetreadfile is complicated. Is there any way to know if the downloaded file is in order.

  22. #22
    Hyperactive Member kazar's Avatar
    Join Date
    Apr 2006
    Location
    UK
    Posts
    323

    Re: internetreadfile

    use the inet control.
    VB Code:
    1. filestr = Inet1.OpenURL("address")
    2.  
    3. Open "C:\savefile.html" for output as #1
    4.     Print #1, filestr
    5. Close
    KAZAR

    The Law Of Programming:

    As the Number of Lines of code increases, the number of bugs generated by fixing a bug increases exponentially.
    __________________________________
    www.startingqbasic.co.uk

  23. #23

    Thread Starter
    Addicted Member
    Join Date
    Feb 2006
    Location
    Hyderabad, India
    Posts
    233

    Re: internetreadfile

    When I use the above only part of the file is being read.
    I did this and it is working fine.
    VB Code:
    1. Private Sub cmdget_Click()
    2. Inet1.URL = surl
    3. Inet1.Execute
    4. End Sub
    5.  
    6.  
    7. Private Sub Form_Load()
    8. Inet1.Protocol = icHTTP
    9. End Sub
    10.  
    11. Private Sub Inet1_StateChanged(ByVal State As Integer)
    12.  
    13. Static i As Integer
    14. Dim stemp As String
    15. Dim bdone As Boolean
    16. Dim fh As Long
    17.  
    18. stemp = vbNullString
    19. bdone = False
    20.  
    21. Select Case State
    22. Case icError
    23.   MsgBox ("An error occurred while downloading the information")
    24.  
    25. Case icConnected
    26.   Form1.Caption = "Connected to the site"
    27.  
    28. Case icConnecting
    29.   Form1.Caption = "connecting to the site"
    30.  
    31. Case icDisconnected
    32.   MsgBox ("Disconnected from the site")
    33.  
    34. Case icDisconnecting
    35.   Form1.Caption = "disconnecting from the site"
    36. Case icHostResolved
    37.   Form1.Caption = "host resolved"
    38. Case icNone
    39.   Form1.Caption = "no message"
    40. Case icRequesting
    41.   Form1.Caption = "requesting"
    42. Case icRequestSent
    43.   Form1.Caption = "request sent"
    44. Case icResolvingHost
    45.   Form1.Caption = "resolving host"
    46.  
    47. Case icResponseCompleted
    48.   stemp = Inet1.GetChunk(1024, icString)
    49.   DoEvents
    50.  
    51.   Do While Not bdone
    52.     sdata = sdata & stemp
    53.     stemp = Inet1.GetChunk(1024, icString)
    54.     DoEvents
    55.     If Len(stemp) = 0 Then
    56.       bdone = True
    57.     End If
    58.   Loop
    59.   MsgBox ("Received the response in full")
    60.   Text1.Text = sdata
    61.   fh = FreeFile
    62.   Open App.Path & "\musicvideo.txt" For Output As fh
    63.   Print #fh, sdata
    64.   Close #fh
    65.  
    66. Case icResponseReceived
    67.   i = i + 1
    68.   Form1.Caption = "received the response " & CStr(i)
    69.  
    70. Case icReceivingResponse
    71.   Form1.Caption = "Receiving response"
    72. End Select
    73. End Sub
    Would you suggest anything else for still better performance?

  24. #24
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171

    Re: internetreadfile

    What do you mean still better performance? To read/download the file faster?


    Has someone helped you? Then you can Rate their helpful post.

  25. #25

    Thread Starter
    Addicted Member
    Join Date
    Feb 2006
    Location
    Hyderabad, India
    Posts
    233

    Re: internetreadfile

    Yes . Faster download and to see if any part of code is not necessary. And if you have patience to start all over again with internetreadfile: Why is it that it gets the data with duplications and other distortions?

  26. #26
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171

    Re: internetreadfile

    Sorry, but I have no idea why the downloaded content wouldn't match the original source... It shouldn't since it just downloads the html code from what I understand, right? So after that, opening the downloaded data in a browser it should be identical?

    As for speed, the only restriction should be your internet connection. There is no way to speed that up at all...


    Has someone helped you? Then you can Rate their helpful post.

  27. #27

    Thread Starter
    Addicted Member
    Join Date
    Feb 2006
    Location
    Hyderabad, India
    Posts
    233

    Re: internetreadfile

    I am attaching the zipped project. In that google.com homepage is downloaded using both the internetreadfile and inet. Result from each will be written a separate file with names usingapi.html and usinginet.html.
    When I open them in IE. Result from Inet is more coherent and nearer to the actual page when compared with api one. Size of the file is small so there aren't many discrepancies. As the filesize grows so do the distortions.
    Please have a look at the project and let me know if I am doing something wrong with internetreadile method.
    Attached Files Attached Files

  28. #28
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171

    Re: internetreadfile

    Could it be that the site uses CSS and the css file isn't downloaded with the html so when you run it locally it looks wrong?


    Has someone helped you? Then you can Rate their helpful post.

  29. #29
    Hyperactive Member kazar's Avatar
    Join Date
    Apr 2006
    Location
    UK
    Posts
    323

    Re: internetreadfile

    true, but that doesn't explain the discrepancies between api and inet
    KAZAR

    The Law Of Programming:

    As the Number of Lines of code increases, the number of bugs generated by fixing a bug increases exponentially.
    __________________________________
    www.startingqbasic.co.uk

  30. #30
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171

    Re: internetreadfile

    Quote Originally Posted by kazar
    true, but that doesn't explain the discrepancies between api and inet
    Good point, both should have to be equally wrong I'm out of ideas


    Has someone helped you? Then you can Rate their helpful post.

  31. #31

    Thread Starter
    Addicted Member
    Join Date
    Feb 2006
    Location
    Hyderabad, India
    Posts
    233

    Re: internetreadfile

    Ok, we don't seem to be making much headway with this thread. I will mark it , "resolved with inet". If I come to know why internetreadfile is giving problems , I will update this thread.

  32. #32

    Thread Starter
    Addicted Member
    Join Date
    Feb 2006
    Location
    Hyderabad, India
    Posts
    233

    Re: [Resolved with inet control]internetreadfile

    I have to admit that I have been lazy. Using google I found this bit of code, which looks like vbscript. I made few changes so that it confirms to vb.
    Here is the code
    VB Code:
    1. Dim hopen As Long, hfile As Long, bytesread As Long
    2. Dim buffersize As Integer
    3. Dim sbuffer As String, sresult As String
    4. Dim bOk As Boolean
    5. Static count As Integer
    6.        
    7. buffersize = 1024
    8.     'Create an internet connection
    9. hopen = InternetOpen(App.EXEName, INTERNET_OPEN_TYPE_DIRECT, vbNullString, vbNullString, 0)
    10.     'Open the url
    11. hfile = InternetOpenUrl(hopen, surl, vbNullString, ByVal 0&, INTERNET_FLAG_RELOAD, ByVal 0&)
    12.     'Open destfile For Output As #1
    13.    
    14. bOk = True
    15. sresult = vbNullString
    16.  
    17. Do While bOk
    18.   sbuffer = Space(buffersize)
    19.   bytesread = 0
    20.   bOk = InternetReadFile(hfile, sbuffer, buffersize, bytesread)
    21.   If (bytesread > 0) Then
    22.     sresult = sresult & Left$(sbuffer, bytesread)
    23.   End If
    24.   bOk = ((bOk = True) And (bytesread > 0))
    25.   DoEvents
    26.   count = count + 1
    27.   Form1.Caption = CStr(count)
    28.  
    29. Loop
    30.  
    31. txtdata.Text = sresult
    32.  
    33. fh = FreeFile
    34. Open App.Path & "\usingapi.html" For Output As fh
    35. Print #fh, sresult
    36. Close #fh
    37.  
    38. InternetCloseHandle hfile
    39. InternetCloseHandle hopen
    40. MsgBox "Download complete", vbOKOnly + vbInformation
    And this is the link.
    I didn't find any difference in downloaded data using this code and Inet control. I would be glad if you can confirm it.

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