Contents / Reference section / Previous chapter / Next chapter / Index


37 How to merge two BASIC programs

There are a number of ways of merging two BASIC programs together. Two are given below. In either case the line numbers should not clash unintentionally.

In order to correctly merge two programs together it is necessary to save one of them (the shorter one preferably), as an ASCII file rather than in the usual compressed format. This ASCII version of the program is then merged into the longer program using the command *EXEC. Suppose we wish to merge the program SHORT into the program LONG. First, load in the first program

LOAD "SHORT"

and then create an ASCII version by typing in the next three lines

*SPOOL "SHORT2"

LIST

*SPOOL

This produces an ASCII version of the program. The ASCII version is called SHORT2

Now load in the big program by typing

LOAD "LONG"

This loads the long program

and lastly merge in the small program

*EXEC "SHORT2"

This merges the short program

The command

*SPOOL "SHORT2"

informs the computer that anything that it outputs to the screen is also to be sent to a cassette (or disc, etc.), file called SHORT2. When the computer lists the file it therefore creates an ASCII listing on cassette. The command *SPOOL without a filename is used to end or close the spooled file.

Having created the ASCII version of SHORT called SHORT2, the user then loads the file LONG. The command *EXEC "SHORT2" tells the computer to read in the file SHORT2 as if it were getting characters from the keyboard. If the file SHORT2 contains line numbers (as it does), then these lines will just be added to the BASIC program. Of course, a line number read in from SHORT2 will replace any line with an identical line number in LONG, so it is normal to renumber the two programs SHORT and LONG so that the line-numbers don't clash.

A rather quicker (and "dirtier") method is given below - but if you use this method you must make sure that the second program that you loaded in uses larger line numbers than the first program. You will get predictable but surprising results if not.

Firstly load the program (with the lower line numbers) in the normal way. Then get the computer to print, in hex, the top­of­program address less 2 by entering

PRINT ~TOP-2

Call the resultant number XXXX. Then enter

*LOAD SHORT XXXX

to load the program SHORT (or whatever you have called it) in above the first program. Finally type END to get the computer to sort its internal pointers out. A typical dialogue might look like this - assuming that one program is called ONE and the other is called TWO.

>LOAD"ONE"

>PRINT~TOP-2

195F

>*LOAD TWO 195F

>END

This method is very easy but you must look after the line numbers.

Exit: BBC Microcomputer User Guide; Kasoft Typesetting; Archer


The BBC Microcomputer User Guide was written by John Coll and edited by David Allen for the British Broadcasting Corporation.

Optical character recognition and original formatting effort by Mark Usher.

HTML version maintained by: Kade "Archer" Hansson; e-mail: archer@dialix.com.au

Last updated: Monday 12th February 2001