Here's a nice little UserControl you can drop into any VB5 or VB6 project that does just
one thing, but does it very well and without complaint. You can use NetGrab to
download any* file from the internet (or the local file system, for that matter)
into a Byte array within your process. Also included is a SaveAs method, so you
can write the resulting bytes directly to file, but only if desired.
The advantages of using AsyncRead are several. Most often, the "simple"
answer to the very common problem of downloading any random file is to call the
URLDownloadToFile API.
However, using that call asynchronously isn't for the feint of heart. Plus, this
and every other alternative introduces external dependencies, some more likely
to be built-in than others.
The native capability of VB5/6 UserControls to do asynchronous downloads is
seemingly an almost unknown capability. With this little demo, I hope to show
you just how simple it truly can be. The included UserControl is written to just
do a single download at a time. Although nothing would prevent you from using
multiple instances for multiple simultaneous downloads, you could also modify
this one ever so slightly to support multiple streams. The ticket would simply
be in keeping a dynamic collection of keys, as demonstrated in my NetCam demo.
Note on Conditional Compilation
UserControls in VB6 offer a few extra capabilities with the AsyncRead method
and events. Be sure to toggle the conditional compilation constant at the top of
the CTL module if you want to use it in VB5.
* Actually, there's no provision for downloading files that require
credentials. Strictly a KISS project.