SB BBC @ GBR Oldie hints/tips #157-159 Hints and tips from the archives of Wakefield BBC Micro User Group... 157. Calendar functions ~~~~~~~~~~~~~~~~~~ The first of these, FNnumdays at line 1040, is derived from a short Function I saw on Micronet, credited to Frank McAree. It returns the number of days in month m% in year y%; eg PRINT FNnumdays(7,1987) would print the number of days in July 1987. It takes account of all Leap Years, which the original didn't. Years divisible by 4 are Leap years, except for those divisible by 100 but not by 400. Eg the year 1900 wasn't a Leap year, but 2000 will be. The present Gregorian calendar system dates from 1752 in most countries; before that it was chaos! The second, FNday at line 1070, is one refined from an Acorn User program by Robin Newman. It returns the day of the week on the date d%,m%,y%; eg PRINT FNday(22,3,1986) would print the day of the week on 22nd March 1986 as a string, "Sat". If however, you want the day as a complete word string, eg "Saturday" rather than "Sat", then put the full words in line 1050, padded with trailing spaces to 9 characters each, ie "Saturday-Sunday---Monday---Tuesday--WednesdayThursday-Friday---", ("-" represents a space), and alter both the figures "3" to "9". If you would rather it returned the day of the week as a number, then alter line 1050 to =day% . This gives 0 for Saturday, 1 for Sunday and so forth, so if you would prefer 7 for Saturday instead of 0, then alter line 1050 to =day%-(day%MOD7=0)*7 . (This is more elegant and structured than using IFday%=0THEN=7 ELSE=day% .) These two Functions can be used quite independently, but the Procedure PROCcalendar at line 1000 shows just one way in which they might be used together. It displays a crude calendar for month m% in year y%, eg PROCcalendar(7,1987) for July 1987. 1000 DEFPROCcalendar(m%,y%):LOCALd% 1010 FORd%=1TOFNnumdays(m%,y%):PRINTFNday(d%,m%,y%)" ";d%:NEXT 1020 ENDPROC 1030 : 1040 DEFFNnumdays(m%,y%) 1050 =30+ABS((m%>7)+(m%MOD2))+(m%=2)* (2+(((y%MOD4)=0AND(y%MOD100)>0)OR((y%MOD400)=0))) 1060 : 1070 DEFFNday(d%,m%,y%):LOCALday% 1080 IFm%<3THENm%=m%+12:y%=y%-1 1090 day%=d%+2*m%+INT(0.61*(m%+1))+y%+y%DIV4-y%DIV100+y%DIV400+2 1100 day%=day%MOD7 1110 =MID$("SatSunMonTueWedThuFri",day%*3+1,3) 158. Multiple windows ~~~~~~~~~~~~~~~~ It is possible to give the illusion that there are several independent text windows defined on the screen simultaneously. As soon as you define a new text window, the previous one is 'forgotten'. However, as long as the program 'remembers' where the cursor was, the same window can be redefined later, and the cursor put back in its original position. The short demonstration program below displays two independently scrolling windows on the screen. VDU31,x,y is equivalent to PRINTTAB(x,y); and the term IFSGNRND=1THEN is used to make the two windows scroll at different, varying rates. Omit this term, leaving just VDURND(95)+31 to see what I mean. 100 p1%=0:v1%=0:p2%=0:v2%=0:MODE7:VDU23,1,0;0;0;0; 110 REPEAT:PROCwindow1:PROCvdu:PROCwindow2:PROCvdu:UNTILFALSE 120 : 1000 DEFPROCwindow1:p2%=POS:v2%=VPOS 1010 VDU28,0,11,18,0:VDU31,p1%,v1%:ENDPROC 1020 : 1030 DEFPROCwindow2:p1%=POS:v1%=VPOS 1040 VDU28,21,24,39,13:VDU31,p2%,v2%:ENDPROC 1050 : 1060 DEFPROCvdu:IFSGNRND=1THENVDURND(95)+31 1070 ENDPROC 159. Accelerating step rate ~~~~~~~~~~~~~~~~~~~~~~ This is a simple program by Andrew G8YHI, to demonstrate an idea. If you press and hold either the Up or Down cursor key, a number on the screen will be incremented or decremented accordingly. The longer you hold the key down, the faster the number changes. This would enable values to be altered by large amounts easily and quickly, whilst still allowing 'fine tuning'. Perhaps some enterprising person could tidy this up into a more general-purpose procedure? 10 CLS:X=33:VDU23,1,0;0;0;0; 20 REPEAT:PROCchange:UNTILFALSE 30 : 100 DEFPROCchange:TIME=0:REPEAT 110 IF INKEY(-58) THEN X=X+(TIME/2000) ELSE IF INKEY(-42) THEN X=X-(TIME/2000) 120 Y=INT(X):PRINTTAB(10,10)Y:UNTILINKEY(-129):ENDPROC 73 Rick G4BLT @ GB7WRG