# Directives

BEGIN | Reset Files and Variables

## Format

BEGIN[ [ EXCEPT ] varlist | * ]

Where:

varlist An optional list of variables.

## Description

The BEGIN directive performs the following functions:

1. Closes all Local files currently open. (Global files remain open unless using BEGIN *).

#### Note:
In closing all files, the main console window will be reset if the 'WK' system parameter is not on. The reset consists of dropping all windows and all non-global graphical user interface controls. In addition, the menu_bar is reset to its default "Enabled" state.

2. Resets PRECISION to the default value of 2 (the value set in the 'PD' system parameter).

3. Clears local variables. (Global variables are not affected unless using BEGIN *.)

> (a) All variables if no varlist appears on directive
> (b) Only those in varlist if no EXCEPT clause given
> (c) All but those in varlist if EXCEPT clause present
> See Example.

4. Sets ERR, RET, and CTL to zero.

5. Clears FOR/NEXT, GOSUB/RETURN, WHILE/WEND, etc. stack.

6. Resets pointer to the first DATA item in the program.

The BEGIN * directive also closes all global files and clears all global variables including those defined using the GBL function.

#### Note:
When executed within an object (in Object Oriented Programming), the BEGIN directive will clear all of the object's properties, along with standard variables, and will close any standard local files and files owned by the object.

(The ability to use * to clear all global files/variables was added in PxPlus v7.10.)

## See Also

CLEAR Reset Variables
RESET Reset Program State
START Restart Session
ERR( ) Test Error Value
CTL Control Code: Key to End Input
RET Operating System's Last Error Code

## Example

The following examples are from step 3 above:

3(a) begin
3(b) begin A3$,B3$,C3,D3
3(c) begin except CST_ID$,TX_VAL,TX_TBL${all}