Recovering from Cancel

 

By default, if a user cancels out of a dialog, the label :CANCEL will be searched for in the WIL program, and, if found, control will be transferred there. If no label :CANCEL is found, processing simply stops. This allows the program developer to perform various bits of cleanup processing after a user presses Cancel.

The function IntControl 72 lets you specify what should happen when the next Cancel event occurs in the script. This allows the program developer to perform cancel processing, if a user presses Cancel, in any dialog. When processing goes to :CANCEL, the following WIL variables are automatically set:

 

 

§         Notes

§         Reference

§         Step by step guide to learning WIL

 

  

Variable

Type

Meaning

wberrorhandlerline

string

cancel line (i.e., line in script that caused Cancel) or 0 if the cancel cannot be matched to a particular line.

wberrorhandleroffset

integer

offset into script of Cancel line, in bytes

wberrorhandlerassignment

string

variable being assigned on Cancel line, or "" if none

wberrorhandlerfile

string

name of the currently-executing script

wberrortextstring

string

description of the WIL error

wberroradditionalinfo

string

additional error information, if any

wberrorinsegment

string

line number in the currently executing script or UDF where the Cancel occurred.

wberrorarray

(a)

WIL array with the following elements:

wberrorarray [0] = LastError()

wberrorarray [1] = wberrorhandlerline

wberrorarray [2] = wberrorhandleroffset

wberrorarray [3] = wberrorhandlerassignment

wberrorarray [4] = wberrorhandlerfile

wberrorarray [5] = wberrortextstring

wberrorarray [6] = wberroradditionalinfo

wberrorarray [7] = wberrorinsegment

wberrorarray [8] = wberrorhandlerlinenumber

wberrorarray [9] = line number in the UDF where the cancel occurred or 0.

wberrorarray[10] = a positive number if reported line numbers are accurate, zero (0) if possibly inaccurate or -1 if run from WinBatch Studio, in which case both wberrorarray[8] and wberrorarray[9] will contain the line number of the cancel in the UDF.

wberrorarray[11] = used to set return value of the function the cancel occurred on.

 

Note: The Windows operating system offers many alternatives, for canceling a dialog: pressing the Cancel button, typing Esc, Alt-F4, and some others.

See the Basic Script Template below for an example of trapping more than one :CANCEL label.

 

Script Template

Here is a suggested template of a script handling multiple cancels:

 

;TITLE:

;DATE:

;AUTHOR:

;VERSION:

;UPDATED:

;PURPOSE:

 

IntControl(72,2,0,"",0)

abc=Pause("Pause","one")

Message("ABC is",abc)

 

def=Pause("Pause","two")

Message("def is",def)

 

Exit

 

:CANCEL

%wberrorhandlerassignment% = 9999

IntControl(72,2,0,"",0)

return