String.GetFormattedSize

string String.GetFormattedSize (

number SizeInBytes,

number Format = FMTSIZE_AUTOMATIC,

boolean ShowCommas = true )

Example 1

sFormatted = String.GetFormattedSize(nBytes, FMTSIZE_AUTOMATIC, true);

Converts the value in nBytes from number of bytes to a formatted string. The best format based on the size is automatically chosen, and is stored in sFormatted.

Example 2

-- Callback function for HTTP.Download
function DownloadCallback (nDownloaded, nTotal, TransferRate, SecondLeft, SecondsLeftFormat, Message)
-- Convert total and downloaded bytes into formatted strings
sDownloaded = String.GetFormattedSize(nDownloaded, FMTSIZE_AUTOMATIC, true);
sTotal = String.GetFormattedSize(nTotal, FMTSIZE_AUTOMATIC, true);

-- Set statusdlg title and message
StatusDlg.SetTitle("Downloading . . . ");

-- Output time left, formatted.
StatusDlg.SetMessage("Currently downloading file . . . Time Left: " .. SecondsLeftFormat);

-- Output formatted sizes to user through statusdlg status text
StatusDlg.SetStatusText("Downloaded: " .. sDownloaded .. " / " .. sTotal);

-- Set meter range (max range = 65534)
StatusDlg.SetMeterRange(0, 65534);

-- Set meter position (fraction downloaded * max meter range)
StatusDlg.SetMeterPos((nDownloaded / nTotal) * 65534);
end



-- Show the StatusDlg
StatusDlg.Show(0, false);

-- Download a file from the internet to the user's computer
-- Uses DownloadCallback() as the callback function
HTTP.Download("http://www.yourdomain.com/downloads/update.exe", _TempFolder .. "\\update.exe", MODE_BINARY, 20, 80, nil, nil, DownloadCallback);

-- Hide the StatusDlg
StatusDlg.Hide();

Downloads a file from the internet onto the user's computer. The callback function "DownloadCallback" controls the Status Dialog.

See also: Related Actions