# CLEAR Reset Variables

> Source: https://manual.pvxplus.com/directives/clear

## Formats

|  |  |
| --- | --- |
| 1\. [Clear](https://manual.pvxplus.com/directives/clear#Mark6)*,* [Reset](https://manual.pvxplus.com/directives/clear#Mark6)*:* | **CLEAR\[ \*\] \[ \[ EXCEPT** **\]** *varlist* **\]** |
| 2\. [Clear Composite String](https://manual.pvxplus.com/directives/clear#Mark8)*:* | **CLEAR** *template$* |

***Where:***

|  |  |
| --- | --- |
| *template$* | Name of a variable **DIM**ensioned as a string template. String expression. |
| *varlist* | An optional list of variables. |

## Description

The **CLEAR** directive performs the following functions:

1\. Resets **PRECISION** to the default value of 2 (the value set in the ['PD'](https://manual.pvxplus.com/parameters/pd) system parameter).

2\. Clears local variables. (*Global variables are not affected unless using CLEAR \*)*

(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](https://manual.pvxplus.com/directives/clear#Mark6)**.

3\. Sets **ERR**, **RET** and **CTL** to zero.

4\. Clears **FOR/NEXT**, **GOSUB/RETURN**, **WHILE/WEND**, etc. stack.

The **CLEAR \*** directive also clears all global variables including those defined using the **[GBL](https://manual.pvxplus.com/functions/gbl)** function. **CLEAR \*** will also accept an **EXCEPT** *varlist* clause to omit specific variables from being cleared.

Note:  
When executed within an object (in [Object Oriented Programming](https://manual.pvxplus.com/pxplus-user-guide/object-oriented-pxplus/introduction)), the CLEAR directive will clear all of the object's properties, along with standard variables.

*(The CLEAR \* directive was added in PxPlus v7.10.)*

## Format 1

***Clear, Reset***

**CLEAR** \[**EXCEPT**\] \[*varlist*\]

***Example:***

The following examples show respectively clearing all variables, clearing only a selected list of variables, and **CLEAR**ing all **EXCEPT** a selected list of variables:

```
clear
clear A3$,B3$,C3,D3
clear except CST_ID$,TX_VAL,TX_TBL${all}
```

## Format 2

***Clear Composite String***  
  
Use this format to clear the value(s) **DIM**ensioned as a string template:

```
clear CUST$

or

clear CUST.NAME$
```

For information on string templates, see [DIM Define Arrays and Strings](https://manual.pvxplus.com/directives/dim).

## See Also

[BEGIN Reset Files and Variables](https://manual.pvxplus.com/directives/begin)  
[RESET Reset Program State](https://manual.pvxplus.com/directives/reset)  
[START Restart Session](https://manual.pvxplus.com/directives/start)  
[ERR( ) Test Error Value](https://manual.pvxplus.com/functions/err)  
[CTL Control Code: Key to End Input](https://manual.pvxplus.com/variables/ctl)  
[RET Operating System's Last Error Code](https://manual.pvxplus.com/variables/ret)
