Basic programming guide, Clear clear s – Remote Processing BASIC for the CX-10 Modbus User Manual
Page 15

BASIC PROGRAMMING GUIDE
2-6
CLEAR
CLEAR S
Syntax:
CLEAR
CLEAR S
Function:
Sets variables to zero, clears stacks
Mode:
Command, run
Use:
CLEAR
CLEAR S
DESCRIPTION
The CLEAR instruction sets all variables to 0 and resets all Basic stacks. ONERR is cleared. Error trapping
must be redeclared after a CLEAR. CLEAR is generally used to clear all variables. CLEAR does not de-
allocate memory allocated to strings by the STRING instruction. It does clear the contents of the strings.
Data put to the stack by PUSH is cleared. CLEAR also resets any FOR-NEXT loops. A C-STACK error is
returned when a NEXT is performed after a CLEAR. CLEAR also resets any GOSUB return addresses.
Use CLEAR to perform a soft reset of a program. Keep in mind that multi-tasking routines are not cleared or
reset using this command. However, if CLEAR is used as part of a multi-tasking program (ON COM$, ON
LINE, etc.), a RETURN will cause a C-STACK error.
CLEAR S resets the control stack (C-STACK) only. This stack is used in loops and subroutines to tell it
where to return to. Use this command to branch (GOTO) out of FOR-NEXT, GOSUB-RETURN, DO-
UNTIL type structures. It can be used in emergency stop situations where nesting of loop structures is not
known. Variables are not cleared using CLEAR S.
RELATED none
EXAMPLE
10
CLEAR TICK(0)
20
ONTICK 1,1000
25
ONERR 500
30
IF TICK(0)<2.5 THEN 30
40
A=TICK(0)/0
50
IF TICK(0) < 3.3 THEN 50
60
CLEAR
70
PRINT "CLEARED"
80
GOTO 80
500
PRINT "IN ERROR"
510
ONERR 500
520
GOTO 50
1000
PRINT TICK(0),A
1010 A=A+1
1020
RETI
>RUN
1
0
2
1
IN ERROR
3
2
4
0
5
1
6
2