- Append a line 32767 to your program holding "32767 DATA 999" (the actual value in that DATA item is totally arbitrary, BTW)
- RENUM 1 TO;1,1
- RESTORE 1
- REPEAT lp: IF EOF : EXIT LP : READ a$ : END REPEAT lp
- lastLine = PEEK_W (\\$94)
- DLINE lastLine
This uses the fact that S*BASIC actually keeps track of the current DATA line number in a basic system variable (\\$94). We make sure the last line of the program is a DATA line, read all DATA as far as possible, then PEEK the current DATA line number and delete the inserted line. After the routine has run, lastLine will hold the next usable line number.
The RENUM in step 2 is to "compress" used line numbers as much as possible, thus will leave your program with lines starting from 1 in 1-steps. If you don't like this, do another RENUM at the end of the routine that renumbers the program to your liking.
If you think someone was as bold as using line # 32767 already, add another RENUM before (1).
You need to read a string in the loop to avoid data type mismatches in possibly already existing DATA lines. Obviously, if your program already has some DATA lines, you'll also need to do a RESTORE 1 after the routine has run (because it has exhausted all the DATA already)
EDIT: Just found that anything but RENUM without arguments (so, 10, 10) will stop the program in SBASIC with no message whatsoever.... - So, it still works which RENUM only, but your range of line numbers is severely limited (I conceive that as a bug in SBASIC, BTW). Apparently, SBASIC doesn't "RENUM" the current line it is in. But you should be able to arrange your programs that they survive a RENUM.