SB BBC @ GBR Oldie hints/tips #001-010 Hints and tips from the archives of Wakefield BBC Micro User Group... 1. BASIC editing ~~~~~~~~~~~~~ If you are editing a BASIC program, you can find out what is the last line number in the program as follows: Hold down SHIFT and CTRL together, press ESCAPE twice in succession, and finally release SHIFT and CTRL. This even works on an Archimedes/A3000! 2. Listings ~~~~~~~~ To stop listings and any other screen output* whizzing past too quickly, hold and down together. Alternatively, from the BASIC '>' prompt, press to engage paged mode, and press to continue scrolling. Cancel with . This also works fine on an Archimedes. * eg packet messages! 3. Filling up strings ~~~~~~~~~~~~~~~~~~ It is sometimes necessary to fill-up or 'pad' out strings to a fixed length. For example, you may want numbers to print out as 0045, 0001 etc., or you may want to add leading or trailing spaces onto character strings. The first example gives the obvious method, whereas the second shows a more elegant method which avoids the use of an IF statement. The third example shows a similar method in the form of a Function, with the addition that you can specify the amount of padding and the padding character to be used - it doesn't have to be a number. 30 IF LEN(X$)<4 THEN X$="0"+X$:GOTO 30 30 X$=STRING$(4-LEN(X$),"0")+X$ 10 INPUT"Enter up to 5 digits "A$ 20 A$=FNpad(A$,5,"0"):PRINT A$:END 30 : 100 DEFFNpad(st$,len%,char$):=STRING$(len%-LEN(st$),char$)+st$ 4. Randomize ~~~~~~~~~ To 'scramble' the Beeb's random number generator properly, you can simulate the RANDOMIZE function of some other BASICs. Incorporate the dummy expression randomize=RND(-TIME) at the beginning of your program. This also works on an Arc/A3000. 5. Self-validating input ~~~~~~~~~~~~~~~~~~~~~ Try incorporating this sort of input routine into your own program. There is nothing special about the particular line numbers used. 1000 PRINT"Do you want another game ? "; 1010 ON INSTR("YyNn",GET$) GOTO 1020,1020,1030,1030 ELSE 1010 1020 REM Back to start of program. 1030 END 6. Shortened 'IF' statement ~~~~~~~~~~~~~~~~~~~~~~~~ In most cases, the statement IF A<>0 THEN etc. can be shortened to just IF A etc. The "<>0" is implied, provided A can only be zero, or +1 or more, or -1 or less. In the 'before' and 'after' example below, note the space after the variable "A" in the second version. This space would be unnecessary if the variable were "A%" instead. 100 IF A<>0 THEN G=5:GOTO 70 100 IF A G=5:GOTO 70 (Note the space after the A!) 7. Simple bleep ~~~~~~~~~~~~ If you want a short 'bleep' in your program, you can use VDU7 or PRINT CHR$(7) instead of a SOUND statement. VDU7,7 etc would give a longer bleep. 8. VDU7 bleep ~~~~~~~~~~ You can alter the nature of the VDU7 'bleep' as follows. *FX210,1 turns it off, and *FX210 turns it on again. You can alter the pitch with *FX213,P where "P" is a number from 0 to 255, (default value is about 100). Similarly, you can alter the duration with *FX214,D (default value about 7). You can change sound channel or 'voice' with *FX211,N where "N" is 0 to 3, (normally 3). Thus, if you try *FX211,0 you will get a sort of explosion noise, and *FX211,3 will restore it to a bleep. You can test the bleep by pressing ; quicker than typing VDU7. 9. Key-pressed check ~~~~~~~~~~~~~~~~~ You can check to see if a specific key is being pressed at a particular instant with a negative INKEY statement. For example, you can test the space-bar with IF INKEY(-99) THEN... However, if you want to see if ANY key is being pressed, (though not the red keys or or ), then use this command. It works in the opposite sense to the other negative INKEY commands, hence the inclusion of the word "NOT". IF NOT INKEY(-129) THEN ... 10. Input line ~~~~~~~~~~ An ordinary INPUT statement will strip any leading spaces off strings, and will not accept commas within a string. The latter is because you can use commas to separate your replies, instead of pressing each time, eg BLOGGS,45,MALE . You are reminded that the alternative command INPUTLINE will accept commas and leading spaces. You can easily strip the leading spaces off afterwards, if they are a problem. 73 Rick G4BLT @ GB7WRG