CHAIN                                                                  Statement

CHAIN pathname[, reset]

Description

CHAIN loads a program into the environment and begins execution. The required component, pathname, is a string expression that specifies the absolute path name of the program to load and execute. The required component, reset, is a boolean expression that specifies whether the environment should be completely reset (all constants, variables, and procedures cleared from memory) before loading and executing the new program. Use a BYE statement after CHAIN to complete execution of the calling program.

If reset is TRUE, execution continues in the original program until it stops executing. All variable and subroutines are reset and the new program is then loaded and run.

If reset is FALSE, then the new program is run immediately, with all variables and subroutines remaining intact. When the new program ends, the original program continues from the next statement. Variables and subroutines added or modified in the CHAINed program will remain.

Hint: Use CHAIN with reset FALSE to "include" common program statements in multiple programs.

Example

'Program A

PRINT "This is program A"

A=100

CHAIN "B.nsb",TRUE 'reset the environment

PRINT "This is program A after CHAIN"

PRINT A

'Program B

PRINT "This is program B"

PRINT A

A=200

Output

This is program A

This is program A after CHAIN

100

<screen clears>

This is program B

<no value prints as A is undefined inprogram B>

Example 2

'Program A

PRINT "This is program A"

A=100

CHAIN "B.nsb",FALSE 'don't reset the environment

PRINT "This is program A after CHAIN"

PRINT A

'Program B

PRINT "This is program B"

PRINT A

A=200

Output

This is program A

This is program B

100

This is program A after CHAIN

200

Related Items

EXECUTE