OLE – HTML GET and ADODB

This script uses OLE to get a HTML file from the web and then save that file on the local file system.

The following function is part of the executable, and can be found in the System macros Panel.

function DownLoader ( OnlineURL, OfflineFileName , optional absFileName = 0 )
' DOWNLOAD a online file, at the URL, to your DeskTop
' e.g. message = DOWNLOADER ( "https://ripetech.com/wp-content/uploads/2018/02/WriterDemo.txt" , "WriterDemo.txt" )
Dim objHTTP = CreateObject("Microsoft.XMLHTTP")
' or
' Dim objHTTP = CreateObject("MSXML2.XMLHTTP")
' both work on my system!
If ( ! objHTTP ) THEN
Message ="Could not create object"
exit function
End IF
Dim res
res = objHTTP.Open ( "GET", OnlineURL , False)
objHTTP.send
dim waitLoop = 50
DO
res = objHTTP.status
if res == 200 THEN ' HTML code for finished
waitLoop = 0
ELSE
waitLoop = waitLoop - 1
End IF
Loop while waitLoop
dim rt = objHTTP.responseBody
Dim oADOStream = CreateObject("ADODB.Stream")
If ( ! oADOStream ) THEN
Message ="Could not create object"
Set objHTTP = Nothing
exit function
End IF
oADOStream.Type = 1
oADOStream.Mode = 3
oADOStream.Open
oADOStream.Write (rt)
dim SaveAsFIle = IIF ( absFileName , OfflineFileName , getFOlderPath(0) & "\\" & OfflineFileName )
if isFile (SaveAsFIle) Then
DeleteFile (SaveAsFIle)
End IF
oADOStream.SaveToFile ( SaveAsFIle)
oADOStream.Close
Set oADOStream = Nothing
Set objHTTP = Nothing
DownLoader = SaveAsFIle
END FUNCTION

It can be used to download a file, from a Web site, to a file on the local file system.

e.g. dim myGuitar = downloader ("https://ripetech.com/wp-content/uploads/2017/10/DSC08618-1200x1793.jpg", "Guitar.jpg")

It is called by one of the SOB demos, available via the menu help: