MSI Factory 2.3

Application.SetLastError

Application.SetLastError

This is the first topic This is the last topic  

Application.SetLastError

This is the first topic This is the last topic  

OverviewExamples

Application.SetLastError (

number ErrorCode )

Example 1

Application.SetLastError(0); -- set the last error to "no error occurred"

Sets the last error code to 0, signalling that "the last action was successful." (The text after the "--" in this example is just a comment.)

Example 2

Application.SetLastError(3245);

Sets the last error code to 3245.

Example 3

-- Create custom error table

tCustomErrors = {};

tCustomErrors[10001] = "Under 13 Years of Age";

tCustomErrors[10002] = "Numeric Age > 0 Required";

 

-- Prompt user for their age

sAge = Dialog.Input("User Input", "Enter your age");

 

-- Convert age string to number

nAge = String.ToNumber(sAge);

 

-- Check for error one criteria

if nAge < 13 then

   Application.SetLastError(10001);

end

 

-- Check for error two criteria

if nAge <= 0 then

   Application.SetLastError(10002);

end

 

-- Get the last error

nLastError = Application.GetLastError();

 

-- was the last error 'success' (0)?

if nLastError == 0 then

   --No error occured, do something here

else

   --An error occured

   Dialog.Message("Error", "Error (" .. nLastError .. "): " .. tCustomErrors[nLastError] .. ".", MB_OK, MB_ICONEXCLAMATION, MB_DEFBUTTON1);

end

This example uses custom error codes to determine if the conditions fail and to display a more appropriate error message.

See also: Related Actions


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