NAME

chain - transfer control to another BASIC program

SYNOPSIS

chain FileSpec

DESCRIPTION

Chain overlays the currently executing BASIC program with a different BASIC program.  FileSpec may be any string expression, and specifies the name of a file containing a compiled BASIC program which will replace the program currently executing.  The text area (instructions) of the original program is irrevocably lost.  The data area (variables) of the original program may be copied to the new program through the use of the unlabelled common declaration. 

Default variable types set up in the original program via defint, defsng, defdbl, and defstr are unknown to the new program.  Similarly, functions defined with def fn are defined only in the source file in which the definitions occur. 

Open files remain open across a chain operation. 

EXAMPLE

	defint i, k
	dim a$(25, 25)
	common a$()
	for i = 0 to 25
		for k = 0 to 25
			print i, k, spc(10)
			a$(i, k) = str$(i)
			print a$(i, k)
		next k
	next i
	chain "code2"
In the example above, the array a$() is declared as (unlabelled) common.  This allows the values of a$() at the time of the chain operation to be passed to the program "code2" in order to serve as initialization values for a similar array that it also declares as common.  Here is what the source for "code2" might look like:
	dim a$(25, 25)
	common a$()
	print
	for i = 0 to 25
		print a$(i, 1)
	next i
	end

SEE ALSO

common

USAGE NOTES

In Basmark QuickBASIC, variables are passed serially rather than being memory-mapped.  Thus, in case of a mismatch between common areas in two programs which participate in chaining, the results may differ from the Microsoft compiler. 

Because the compiler has no knowledge of modules other than the one it is compiling, the unlabelled common data preserved across a chain is limited to that declared in the main module. 

DIAGNOSTICS

An "Internal error" occurs if anything goes wrong in the chaining procedure.  This includes the case of a non-existent FileSpec. 

from The Basmark QuickBASIC Programmerís Manual by Lawrence Leinweber