DOWNLOAD function

Purpose:

DOWNLOAD will connect to the Internet and download a file from a specified URL to a specified path\filename.

Syntax:

RetVal = DOWNLOAD(Url AS STRING, LocalFileName AS STRING)

Return Value:

  • Data type: INTEGER
    RetVal If the function succeeded, 1, otherwise, 0.

Parameters:

  • Data type: STRING
    Url The URL of the file to be downloaded.
  • Data type: STRING
    LocalFileName The file path\name save location for the downloaded file.

BCX Console Sample Programs using the DOWNLOAD function.


GETHTTPFILESIZE function

Purpose:

GETHTTPFILESIZE will get the size of a file from a specified URL.

Syntax:

RetVal = GETHTTPFILESIZE(Url AS STRING)

Return Value:

  • Data type: ULONG
    RetVal The size of a file from a specified URL.

Parameters:

  • Data type: STRING
    Url The URL of the file to be sized.

DOWNLOADTOSTR function

Purpose:

DOWNLOADTOSTR will connect to the Internet and download a file to a specified string.

Syntax:

SaveString = DOWNLOADTOSTR(Url AS STRING)

Return Value:

  • Data type: STRING
    SaveString The string in which to save the downloaded file.

Parameters:

  • Data type: STRING
    Url The URL of the file to be downloaded.

Example:

MACRO WarAndPeace = "https://www.gutenberg.org/cache/epub/2600/pg2600.txt"
DIM RemoteFileSize AS ULONG
RemoteFileSize = GETHTTPFILESIZE(WarAndPeace)  ' Obtain the file size 

IF RemoteFileSize THEN
  DIM TheBook$ * RemoteFileSize               ' Create a large string 
  PRINT "Size of 'War and Peace' on server = ", USING$("#", RemoteFileSize), " bytes" ' ~3.3MB File 
  PRINT "Downloading into string variable now ... please wait ..."
  TheBook$ = DOWNLOADTOSTR(WarAndPeace)      ' Download into our string variable 
  BCX_MDIALOG(Example, "'War And Peace'", NULL, 0, 0, 300, 300, 0, 0, "Arial", 12)  ' Read it! 
  END
ELSE
  PRINT "WarAndPeace URL was not found."   ' Hopefully this won't happen 
  PAUSE
  END
END IF

BEGIN MODAL DIALOG AS Example
  SELECT CASE CBMSG
    '****************** 
  CASE WM_INITDIALOG
    '****************** 
    STATIC hRichEdit AS HWND
    hRichEdit = BCX_RICHEDIT(0, CBHWND, 12345, 10, 10, 280, 280)
    SETWINDOWRTFTEXT(hRichEdit, TheBook$)
    CENTER(CBHWND)
    FUNCTION = TRUE
    '****************** 
  CASE WM_QUIT, WM_CLOSE, WM_DESTROY
    CLOSEDIALOG
    END
  END SELECT
END DIALOG