Application.GetLastError

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().. " in " .. Debug.GetEventContext();

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

Example 3

-- Print the specified file.
File.Print("AutoPlay\\Docs\\MyFile.pdf");

--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 "MyFile.pdf" with the user's default viewer for PDF files (probably Acrobat). If the action fails, the error code message is displayed in a dialog message.

Example 4

-- Confirm that the installation executable should be launched.
result = Dialog.Message("Confirm", "Are you sure you would like to install now?", MB_YESNO, MB_ICONINFORMATION, MB_DEFBUTTON1);

-- If the user clicked the Yes button.
if (result == IDYES) then

    -- Run the installation file.
    File.Run("AutoPlay\\Docs\\setup.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 installation file. If they click the Yes button, the installation 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