You call the
AsyncRead method when you need to download
extensive information (perhaps a bitmap image) for a property or some other feature of your
UserDocument. You call
AsyncRead with three arguments:
-
Target. Despite its name, this argument is a string representing
the path to the source of the downloaded information. Target will usually be an Internet
URL or a path on an Intranet site.
-
AsyncType. This long argument can take
one of three values specifying where you plan to store the information that you are
going to download. This argument will help the download process determine exactly what
download format to use. The possible values of the AsyncType parameter
are:
• vbAsyncTypePicture
(0). You plan to store the downloaded
information in a Picture object such as
the Picture property
of a PictureBox control.
• vbAsyncTypeFile
(1). You plan to store the downloaded
information in a file.
• vbAsyncTypeByteArray
(2). You plan to store the downloaded
information in an array of type Byte.
-
PropertyName (optional). You can use
this third argument to identify the download (this is especially useful if you might
have more than one asynchronous download going on at once).
You can then use the string that you assign here to PropertyName
in the AsyncReadComplete event procedure or in the
CancelAsyncRead method. Despite the term PropertyName, this
argument does not automatically guarantee that the information will be assigned to
a property. You must write code in the AsyncReadComplete event procedure
to do that. Listing 14.8 initiates an asynchronous download from a site on a local network.
You will put the downloaded information into a Picture object, and you will use
the identifier "PRETTYPIX" to identify this download.
LISTING 14.8
USING THE ASYNCREAD METHOD TO INITIATE A DOWNLOAD
UserDocument.AsyncRead
_
"file://g:/Intranet/Graphics/PrettyPix.gif",
_
vbAsyncTypePicture, "PRETTYPIX"
After your code has initiated the asynchronous download, nothing happens until
the download has finished and the AsyncReadComplete event
fires—or until your user or your code decides to cancel the download, as
discussed in the next session.