MSI Factory 2.3

String.GetFormattedSize

String.GetFormattedSize

This is the first topic This is the last topic  

String.GetFormattedSize

This is the first topic This is the last topic  

OverviewExamples

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 status dlg title and message

   StatusDlg.SetTitle("Downloading . . . ");

 

   -- Output time left, formatted.

   StatusDlg.SetMessage("Currently downloading file . . . Time Left: " .. SecondsLeftFormat);

 

   -- Output formatted sizes to user through status dlg 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 status dlg

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 status dlg

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


Learn More: Indigo Rose Software - MSI Factory - Buy Now - Contact Us