121. Merging BASIC programs ~~~~~~~~~~~~~~~~~~~~~~ There is no single command which will merge a program on tape or disc with one in memory. This is a shame, as it is useful to be able to tack Procedures from a 'library' onto new programs being written. Some utility ROMs such as Beebug Toolkit incorporate a merge facility, but there are ways round the problem. Method 1 is considered 'dirty' by the purists, but is very effective. Assuming that the main program is in memory, and that the Procedure or routine which you wish to add is on tape or disc, under the filename "fname". Type PRINT~TOP-2 , and note the 3 or 4 digit Hex number which is printed; I shall represent this as 'nnnn'. Now type *LOAD fname nnnn , followed by OLD , (vital), and the merge is complete. This method adds the Procedure onto the end of the program, regardless of the line numbers. For example, your program may use lines 100-2500, and your Procedure may appear as lines 1000-1050 after line 2500. This looks weird, but can be cured simply by RENUMBERing the program. This oddity is actually very useful, because you don't have to worry about the line numbers in the Procedure clashing with those in the main program but if you don't want to renumber the program, then try method 2. Method 2 is more tedious, but may be better on some occasions. First, load your Procedure or routine into memory. It is a good idea to renumber it at this stage, so that the line numbers will not clash with those in the main program. Now save it as a straight ASCII file, ie character-by-character rather than in compressed BASIC keyword token form. TYPE *SPOOL fname followed by LIST . When the listing stops, type *SPOOL on its own to close the file. If you are saving only one part of a longer program, then type LIST 1000,1050 etc instead of just LIST . Now load your main program into memory and add the Procedure with *EXEC name. You will actually see the lines being added on the screen, together with a couple of "Syntax error" messages, which you may ignore. The lines are being added as if typed very quickly on the keyboard, so any common line numbers will be overwritten and the new lines will appear in the correct order. There is no need to subsequently renumber the program, unless you particularly want to. You can keep a library of these Procedures already in ASCII format, so you don't need to use *SPOOL every time. You can then just *EXEC them into your programs as required, which is fairly convenient. You could store them, each with a different set of lines numbers, but this would be hard to keep track of. Alternatively, store them all with high line numbers, say 30000 upwards and every time you add one to a program, renumber the program so that the highest line number becomes relatively low. In that case, you may find method-1 more suitable.