OnError
- Last UpdatedNov 17, 2021
- 2 minute read
The OnError event executes each time an error message is to be displayed.
Syntax
aaHistClientActiveDataGrid.OnError(integer ErrorNo, ref message ErrStr, ref discrete ShowErrorDlg);
Parameters
ErrorNo
A unique number that corresponds to the error message, which is specified by the ErrStr parameter.
ErrStr
Message to be displayed in the error dialog box.
ShowErrorDlg
Determines whether the error dialog box appears. True = Error dialog box displayed; False = Err dialog box not displayed. The ShowErrorDlg parameter defaults to the value of the ShowErrorDlg property.
Remarks
The OnError event provides a means to intercept an error message and either disable it from showing or change the error message text shown.
For information on error numbers and error text pertaining to each control, see the "Error Messages" section in the chapter for that control.
The OnError event executes prior to the display of any error messages. In your script, you can then capture the error, check the ErrStr parameter, and set the parameter to a new value. You can also translate the same string into a different language. If you want to implement your own error handling, you can suppress the default error dialog by setting the ShowErrorDlg parameter to False.
Example
The following example shows how the event parameter can be set in the InTouch HMI software:
TRErrorNo = #ThisEvent.OnErrorerrorNo; {Assign error number from the event to a tag called TRErrorNo}
IF TRShowErrorDlg == 0 THEN {Checking user preference on showing Error Dialog}
#ThisEvent.OnErrorshowErrorDlg = TRShowErrorDlg; {Do not show any error dialog. A value has been assigned value to the ShowErrorDlg parameter}
ELSE
#ThisEvent.OnErrorshowErrorDlg = TRShowErrorDlg; {Show the Error dialog}
IF UserPreferredDialog == 1 THEN {Check whether user wants his/her own dialog}
IF TRErrorNo == 0 THEN {If the error number from the event is 0}
#ThisEvent.OnErrorerrorString = "General Error"; {Assigning a value to ErrStr parameter of the event.}
ELSE IF TRErrorNo == 1 THEN
#ThisEvent.OnErrorerrorString = "Not able to connect to the specified server.";
ELSE IF TRErrorNo == 2 THEN
#ThisEvent.OnErrorerrorString = "Set the server name first.";
ENDIF;
ENDIF;
ENDIF;
ENDIF;
ENDIF;