SB BBC @ GBR Oldie hints/tips #017-020 Hints and tips from the archives of Wakefield BBC Micro User Group... 17. Program string search ~~~~~~~~~~~~~~~~~~~~~ This is a very useful routine to assist in writing and debugging programs. When you need to search for a character or string of characters in your main program, just press a red user key, enter the string you are looking for, and the routine will immediately tell you all the line numbers where that string occurs, taking only 3 seconds to search an 11k program. (It is very similar to the *FIND facility in Disc Doctor.) It is a greatly improved version of a program originally published in Beebug magazine. This version occupies only 256 bytes of memory, hides away out of sight, and will even survive pressing of the key. You can just forget all about it while you use your Micro for BASIC programs. The only limitation is that you cannot use it with relocated programs, but it works with or without a DFS. First, press and then type in the program exactly as shown, even if it does look rather weird. However, you absolutely MUST omit ALL spaces, with the sole exception of the space inside the quotes in line 40. I have only inserted spaces after the line numbers for clarity, so don't put them in yourself. When you've done that, type PRINT~TOP-PAGE, and check that the answer is "FF". It it isn't, then look again! If all is well, you can SAVE it first, and then type RUN. As soon as the "Enter String" prompt appears, press and then type NEW again. You can then LOAD or type in another BASIC program, and use the micro in the usual way. The only thing is that you should make sure that the red user keys and are not redefined. When you need to search, press and enter the search string. You can search for any character, variable name, Procedure or Function name, punctuation etc., (hence the use of INPUTLINE instead of INPUT, to permit commas). You may get the occasional spurious find for a single character, due to it being confused with tokens. The only thing you cannot search for is a BASIC keyword such as PROC, FOR, IF etc., but you can search for *FX, *OPT etc.. If you do need to search for a keyword, then look up the appropriate Hex token on page 483 of the User Guide. Instead of typing in the keyword itself in response the the prompt, press and , which will move the cursor one space to the right, and then type in the token exactly as given in the User Guide. For example, "COLOUR" has the token FB, so this is what you type in; no more, no less. If you have Teletext Mode 7 colour codes inside PRINT or REM statements, then these can occasionally be mistaken for tokens, but this isn't a big problem. The program works in all modes, and is unaffected by . After pressing , both SEARCH and your main program will still be present; just type NEW if you want to type in another program. If you press , then you will need to type OLD, and RUN again as if you had just started. 10 ONERRORGOTO100 20 *KEY9PAGE=PAGE-&100|MRUN|M 30 *KEY10OLD|MPAGE=PAGE+&100|M 40 B%=PAGE+&101:T%=&A00:INPUTLINE"Enter String",$T% 50 IF?T%=&89THEN$T%=CHR$EVAL("&"+$(T%+1)) 60 REPEATN%=&100*?B%+B%?1:P%=B%+3:B%=P%+P%?-1-3 70 IFLEN$T%>LEN$P%THEN90 80 IFINSTR($P%,$T%)THENPRINTN%; 90 UNTIL?B%=&FF 100 PRINT:PAGE=PAGE+&100 18. Wacky error message ~~~~~~~~~~~~~~~~~~~ For an error message straight out of Monty Python, try to renumber a program by typing RENUMBER 1000,1000 . Another good one happens in VIEW, if you type the command... =>FIELD 27 19. Lock out lower-case ~~~~~~~~~~~~~~~~~~~ On occasions, it can be useful for lower-case letters to be treated the same as upper-case in GET$ statements, to avoid having to test for "Y" and "y" for "YES", etc.. This Function will always return upper-case letters, even if the isn't on. It is written as a Function, which you use: 1000 DEFFNget:=CHR$(GET AND &DF) 20. Pressing user keys in a program ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ You can effectively 'press' a red key on exit from a program, by inserting the right code into the keyboard buffer. In this example, 128 corresponds to key , 129 would be etc.. The key is code 138, and note that this method does not actually cause a Break; this would require the key to be physically pressed by hand. 10 *KEY0 LIST|M 20 *FX138,0,128 30 PRINT"Here is a Listing..." 40 END 73 Rick G4BLT @ GB7WRG