Get Progres of Dowloading File from url from vba

MBMSOFT

Registered User.
Local time
Today, 09:49
Joined
Jan 29, 2010
Messages
90
Now I use wininet.dll library to get file and calculate progres of dowloading action ....
it is something like this:
Code:
Do
      If InternetReadFile(hRequest, VarPtr(Buffer(0)), BUF_SIZE, dwBytesRead) Then
        If WriteFile(hFile, VarPtr(Buffer(0)), dwBytesRead, dwBytesWritten, 0) Then
            ' TODO:// calculate progress
            dwStatus = (dwStatus + dwBytesWritten)
            dwPercent = (dwStatus / dwFileSize) * 100
            Debug.Print dwPercent
            'form1.Caption = dwPercent '<-- change this
Else
            Debug.Print "WriteFile error"; ERR.LastDllError
            Exit Do
        End If
      Else
        Debug.Print "InternetReadFile error"; ERR.LastDllError
        Exit Do ' _leave
      End If
      DoEvents
    Loop Until dwBytesRead = 0

I'm considering is it posible to do that with "WinHttp.WinHttpRequest.5.1" or "Msxml2.ServerXMLHTTP.5.0")
eg:
Code:
Set request = CreateObject("WinHttp.WinHttpRequest.5.1")
    
    lResolve = 5 * 1000
    lConnect = 5 * 1000
    lSend = 0 * 1000
    lReceive = 0 * 1000 'waiting time to receive data from server
    'WinHttpReq.setTimeout 10000
    request.setTimeouts lResolve, lConnect, lSend, lReceive

    With request
      .Open "GET", URL, False
      .send
      ...
    End With
    Set request = Nothing
Any idea, will be helpfull
 
MSXML exposes similar functions as WinHTTP in relation to a http request and it might just be possible with either. I haven't given this much thought but give me a file url resource and I'll see what I can do (when I've got a moment).
 

Users who are viewing this thread

Back
Top Bottom