SB BBC @ GBR Oldie hints/tips #011-013 Hints and tips from the archives of Wakefield BBC Micro User Group... 11. String input function ~~~~~~~~~~~~~~~~~~~~~ This Function is an alternative to using a conventional INPUT statement for strings. You specify the minimum and maximum number of characters in the string, and the Function does the rest. The example given is for 2 and 6 characters respectively, whereas an INPUT statement is effectively for 0 and 255. You will find that you cannot press until you have typed in the minimum number of characters, and that you cannot type more than the maximum. Full use of the and keys is allowed. This Function is quite tricky to type in without errors, so take care. I've only put spaces in for clarity, and you can omit them all except immediately before the word "ELSE". If you want the cursor to remain on the same line after is pressed on a valid string, then omit the final PRINT: in line 140, so that you have just ELSE =I$. 10 PRINT"Enter Name ";:name$=FNinp(2,6):GOTO 10 100 DEFFNinp(min%,max%):LOCALG%,G$,I$:*FX21,0 110 PRINT G$; 120 G$=GET$:G%=ASC(G$) 130 IF(LEN(I$)=max% AND G%<>13 AND G%<>127)OR(((LEN(I$)=0 AND(G%<33 OR G%>126))OR(LEN(I$)0 OR G%<>13))THEN VDU7:GOTO 120 140 IF G%>31 AND G%<127 THEN I$=I$+G$:GOTO 110 ELSE IF G%=127 THEN I$=LEFT$(I$,LEN(I$)-1):GOTO 110 ELSE IF G%<>13 THEN VDU7:GOTO 120 ELSE PRINT:=I$ 12. Number input function ~~~~~~~~~~~~~~~~~~~~~ This is a similar sort of Function for validating numbers which may be more than just a single digit. If the number entered doesn't fall within the required limits, the incorrect entry is erased ready for another try. If you are only interested in integers, then alter the variables figure, min and max by adding a "%" sign on the end. Wierd things happen if you muck about with the cursor editing keys, but you can easily temporarily disable them with *FX4,1 or *FX4,2. Like the previous Function, it really pays off in larger programs, as it saves you having to write separate validation routines for each and every input. You could save the Function with the *SPOOL facility, and *EXEC it into new programs as required. Again, you can omit spaces if you want. 10 CLS:PRINTTAB(7,10)"Enter Width ";:width=FNnumber(18.2,65.7) 20 END 100 DEFFNnumber(min,max):LOCAL P%,V%,figure 110 P%=POS:V%=VPOS:PRINT:REPEAT REPEAT VDU127:UNTIL POS=P% AND VPOS=V%:INPUT""figure:UNTIL figure>=min AND figure<=max: =figure 13. Status functions ~~~~~~~~~~~~~~~~ The first is a useful Function which can be used to test the status of various aspects of the VDU drivers. For example, to check if the screen is in paged mode, then use IF FNstatus(2)=TRUE THEN... To check whether there is a text window defined, then use IF FNstatus(3)=TRUE THEN..., and so on. You can achieve the same result, though not in a proper Tube-compatible way, by Peeking location &D0. Indeed, the only way I know of disabling scrolling, (bit 1), is to directly Poke &D0 with ?&D0=?&D0 OR 2. (Enable it again with ?&D0=?&D0 AND 253.) The second Function returns the current graphic Mode number, and the third Function returns the ASCII code of the character at the present cursor position. You can move the cursor to the required position with PRINTTAB(x,y); or VDU31,x,y. 100 REM ** Returns TRUE if Bit is Set ** 110 : 120 REM 0 - Printer enabled by VDU2 130 REM 1 - Scrolling disabled 140 REM 2 - Page Mode enabled by VDU14 150 REM 3 - Text Window defined by VDU28 160 REM 4 - Not used 170 REM 5 - Text/Graphics cursors joined by VDU5 180 REM 6 - Edit cursor in use 190 REM 7 - VDU drivers disabled by VDU21 200 : 210 DEF FNstatus(bit%):LOCAL A% 220 A%=&75:=-(((USR&FFF4 AND &FF00)DIV&100)AND2^bit%)DIV2^bit% 100 REM ** Returns Graphic Mode ** 110 : 120 DEF FNmode:LOCAL A% 130 A%=&87:=(USR&FFF4 AND &FF0000)DIV &10000 100 REM ** Returns Character at 110 REM flashing cursor position ** 120 : 130 DEF FNchar:LOCAL A% 140 A%=&87:=(USR&FFF4 AND &FF00)DIV &100 73 Rick, G4BLT @ GB7WRG (Downloaded from GB7SAM)