MSI Factory 2.3

Application.GetLastError

Application.GetLastError

This is the first topic This is the last topic  

Application.GetLastError

This is the first topic This is the last topic  

OverviewExamples

number Application.GetLastError (

)

Example 1

nError = Application.GetLastError();

Gets the error code for the last action that was performed, and stores it in a variable named "nError."

Tip: Starting a variable name with "n" is a technique that programmers use to help themselves remember that a variable is supposed to contain a numeric value.

Example 2

errmsg = "Error #" .. Application.GetLastError();

Uses the concatenation operator (..) to form an error message containing the last error code and stores the error message in a variable named "errmsg."

Example 3

-- Print the specified file.

File.Print("C:\\Temp\\Readme.txt"));

 

--Check to see if an error occurred.

error = Application.GetLastError();

 

-- If an error occurred, display the error message.

if (error ~= 0) then

   Dialog.Message("Error", _tblErrorMessages[error], MB_OK, MB_ICONEXCLAMATION);

end

Prints the file "Readme.txt" located in "C:\Temp". If the action fails, the error code message is displayed in a dialog message.

Example 4

-- Confirm that the program executable should be launched.

result = Dialog.Message("Confirm", "Are you sure you would like to launch the application?", MB_YESNO, MB_ICONINFORMATION, MB_DEFBUTTON1);

 

-- If the user clicked the Yes button.

if (result == IDYES) then

 

   -- Run the installation file.

   File.Run("C:\\Temp\\myprogram.exe"), "", "", SW_SHOWNORMAL, false);

 

   -- Check to see if an error occurred when launching the file.

   error = Application.GetLastError();

 

   -- If an error occurred, display an error message to the user.

   if (error ~= 0) then

       Dialog.Message("Error", _tblErrorMessages[error], MB_OK, MB_ICONEXCLAMATION, MB_DEFBUTTON1);

   end

end

Asks the user if they would like to run the application. If they click the Yes button, the application file will be launched using the File.Run action. If the action fails, the error code message is displayed in a dialog message.

See also: Related Actions


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