Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > Communications > WinHTTP OnResponseDataAvailable Event


Reply
 
Thread Tools Display Modes
  #1  
Old 09-29-2008, 07:01 PM
viraco viraco is offline
Newcomer
 
Join Date: Sep 2008
Posts: 8
Default WinHTTP OnResponseDataAvailable Event


can someone instruct me how to construct/use this event... ive never done it before

i just need to find a way to get the size of the downloaded data.

i can already get the file size before downloading but want to make a progress bar... pb1.value = ubound(data())/tSize * 100

Here is the code im using to download a file:
Code:
Dim WinHttpReq As WinHttp.WinHttpRequest

Public Sub DLFile(strHTTPFile As String, strFileDest As String)
Set WinHttpReq = New WinHttpRequest
Dim FNum As Integer
FNum = FreeFile
' Create an array to hold the response data.
Dim d() As Byte
' Assemble an HTTP Request.
WinHttpReq.Open "GET", strHTTPFile, False
WinHttpReq.Send
' Put response data into a file.
d() = WinHttpReq.ResponseBody
Open strFileDest For Binary As FNum
Put FNum, 1, d()
Close FNum
NextFile = True
Set WinHttpReq = Nothing
End Sub
i would like someone to help me make it so i can monitor the size of the data being retrieved for a download progress bar...

thank you in advance...
Reply With Quote
  #2  
Old 09-30-2008, 01:12 PM
dilettante's Avatar
dilettante dilettante is offline
Underclocked lifestyle

Forum Leader
* Guru *
 
Join Date: Feb 2005
Location: Michigan, USA
Posts: 4,184
Default

To do something like update progress you have to use the object asynchronously. As data arrives you write it to disk or assemble it in chunks.

The simple example attached shows how to do this, discarding the response data but logging events as they occur. Note that you don't always get a length returned, so sometimes you have to fake a progress bar.

An example of this would be the page at http://www.google.com/ which is sent with chunked Transfer-Encoding, though the main image on that page is sent with a Content-Length header.
Attached Files
File Type: zip WinHTTP Async.zip (2.5 KB, 163 views)
Reply With Quote
  #3  
Old 09-30-2008, 03:54 PM
viraco viraco is offline
Newcomer
 
Join Date: Sep 2008
Posts: 8
Default

Thank you... working perfectly now
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->