SB BBC @ GBR Oldie hints/tips #038-040 Hints and tips from the archives of Wakefield BBC Micro User Group... 38. Double-height input ~~~~~~~~~~~~~~~~~~~ This is a Function which enables you to INPUT strings in two-tone double-height lettering. You have to pass the following variables into the Function: The prompt or question word(s), the first letters of the top and bottom colours, the X and Y tab positions you want it to start from, and the maximum length. You must enter at least one character before pressing , but if you don't like this restriction, then omit the "OR g%=13" from line 160. The space available for the input is shown by a dotted line. If you don't want this, then omit both STRING$ statements from line 130, and change the 46 to 32 in line 170. The example in lines 10 and 20 gives a good demonstration of this nice little routine, which was adapted from an original passed on by Andrew G8YHI. You may omit all spaces from the listing to save memory space, if you wish. 10 MODE7:N$=FNdhin("Name ? ","G","M",5,10,15) 20 PRINT''''N$:END 30 : 100 DEF FNdhin(prompt$,top$,bot$,x%,y%,len%) 110 LOCAL a$,g%,top%,bot% 120 top%=128+INSTR("RGYBMCW",top$):bot%=128+INSTR("RGYBMCW",bot$) 130 VDU31,x%,y%,top%,141:PRINT prompt$;STRING$(len%,"."): VDU31,x%,y%+1,bot%,141:PRINT prompt$;STRING$(len%,".") TAB(x%+LEN(prompt$)+2,y%); 140 REPEAT 150 g%=GET 160 IF (g%=32 OR g%=13 OR g%=127) AND LEN(a$)=0 THEN VDU7:GOTO 150 170 IF g%=127 THEN a$=LEFT$(a$,LEN(a$)-1):VDU127,10,46,8,11:GOTO 200 180 IF LEN(a$)31 AND g%<127 THEN a$=a$+CHR$(g%) ELSE IF g%<>13 THEN VDU7:GOTO 150 190 VDUg%,10,8,g%,11 200 UNTIL g%=13: =a$ 39. Input with timeout ~~~~~~~~~~~~~~~~~~ In some applications, especially Educational programs, it is useful to have an input routine which "times-out" if no key is pressed for a certain number of seconds. This is possible for single-character routines like INKEY, but not with INPUT. This Function solves the problem, and also enables you to set limits on the string size. You must pass the minimum and maximum lengths allowed, and also the number of seconds for timeout after the last key was pressed. If the routine times-out before you press , then it will act as if it had pressed for you. If, however, you would rather that it returned the null, (or empty), string instead, then see the REM statement. The example in line 10 allows a minimum of 1 character, and maximum of 12, with a 5-second timeout. You may omit all spaces in the listing, if you wish, except those inside quotes. Thanks to Brian Parker G6JPZ for suggesting the idea, which has been incorporated into the routine given in the Golden Oldie Tip #11. 10 PRINT"Enter name ? ";:A$=FNinp(1,12,5):PRINT A$':GOTO 10 20 : 100 DEFFNinp(min%,max%,secs%):LOCAL G%,G$,GI$:*FX15,1 110 TIME=0:PRINT G$; 120 G$=INKEY$(0):G%=ASC(G$) 130 IF TIME>secs%*100 THEN PRINT:VDU7:=GI$ ELSE IF G%=-1 THEN 120 140 REM Alter the =GI$ in line 130 to ="" if string is to be null on timeout 150 IF (LEN(GI$)=max% AND G%<>13 AND G%<>127) OR (((LEN(GI$)=0 AND (G%<33 OR G%>126)) OR (LEN(GI$)0 OR G%<>13)) THEN VDU7:GOTO 120 160 IF G%>31 AND G%<127 THEN GI$=GI$+G$:GOTO 110 ELSE IF G%=127 THEN GI$=LEFT$(GI$,LEN(GI$)-1):GOTO 110 ELSE IF G%<>13 THEN VDU7: GOTO 120 ELSE PRINT:=GI$ 40. Date input routine ~~~~~~~~~~~~~~~~~~ This is a reasonably 'intelligent' Procedure for entering the date in a program. It checks for sensible days, months and years, (1984 to 1999), takes account of the different number of days in each month, and allows for Leap Years. The original was written by a chap called Tim Davies, but I've altered it a bit! You can enter the date in many forms, eg. 27.08.84 or 27-8-84 or 27/8/1984 or 27 8 84 or 27,08,84 and so on. The result is a string, date$, which holds the date in the form 27-AUG-1984, and also three integer variables, d%, m% and y%, which represent the day, month and year. If you do not want the string date$, then change line 1070 to ENDPROC. If you do not want to use the integer variables, then add them to the list of LOCAL variables in line 1000. If you enter an invalid date, a beep will sound, and you will be invited to try again. Note the use of INPUTLINE rather than INPUT, in order to permit commas in the date. 10 PROCdate:PRINT'"Todays Date is "date$'d%,m%,y%' 20 GOTO10 1000 DEFPROCdate:LOCALmx%,I%,d$,m$,y$:*FX21,0 1010 PRINT:REPEAT:REPEATVDU127:UNTILPOS=0:INPUTLINE"Please submit date as DD.MM.YY "date$ 1020 d$=LEFT$(date$,2):IFASC(RIGHT$(d$,1))<48THENm$=MID$(date$,3,2) ELSEm$=MID$(date$,4,2) 1030 y$=RIGHT$(date$,2):d%=VAL(d$):m%=VAL(m$):y%=VAL(y$)+1900 1040 RESTORE1080:FORI%=1TOm%MOD13:READm$,mx%:NEXT 1050 IFy%MOD4=0ANDm%=2THENmx%=29 1060 VDU7:UNTILd%>0ANDd%<=mx%ANDm%>0ANDm%<13ANDy%>1983:*FX21,7 1070 date$=STR$(d%)+"-"+m$+"-"+STR$(y%):ENDPROC 1080 DATA JAN,31,FEB,28,MAR,31,APR,30,MAY,31,JUN,30,JUL,31, AUG,31,SEP,30,OCT,31,NOV,30,DEC,31 73 Rick G4BLT @ GB7WRG