Tutorial 011 Siren and Print Format
Again the programs of this tutorial are developments of some found
in Alan Thomas' "Further Programming for the BBC Micro", where I have
rewritten them to replace GOTO statements and line numbers by means of REPEAT...UNTIL
loops and in some cases procedures (PROCs).
Siren
Turn up the sound on your system then run:
REM Siren after Alan
Thomas
REM FuPrFBBCMicro p.37
MODE8:OFF
a=100
b=135
s=1
v=1
incv=1
REPEAT
FOR i=a TO b STEP s
SOUND 1,-v,i,1
COLOUR ABS(v)
PRINTTAB(i)"£"
NEXT
v = v + incv
IF ABS(v-8)=7 THEN incv=-incv
c=a : a=b : b=c
s=-s
UNTIL FALSE
When you find a keyword such as ABS in the above, you can find out about
it by using the "context sensitive help" in the BB4W editing pane - this is
activated from the icon on the top tool bar which has a symbol containing
a balck arrow and a large question mark. In this case drag the cursor with
its question mark over ABS and click, wherupon you should see a box appear
which tells you that ABS converts its argument (value in brackets) in this
case v-8 into a postive number if it is negative and leaves it positive if
it is already positive.
Change some parameters and discover for yourself how it works!
Field width
@% enables you to set the "field width"which applies differently to the
printing of numbers and strings.
In the following program :
MODE8
@%=4
FOR i=1 TO 20
PRINT RND(999);
NEXT
PRINT
To see how it works alter the value of @% from 4 to 5,8,10,20
In the following you can compare the effects more easily:
MODE8:OFF
REPEAT
READ k : PRINT"@% = ";k
PRINT
@%=k
FOR i=1 TO 20
n=RND(999)
PRINT n;
NEXT
PRINT'
UNTIL k=20
END
DATA 4,5,8,10,20
Incidently, you can copy the text from your screen to the clipboard by Holding
down the Control key then pressing th TAB key (the one just above the Caps
Lock Key on the left of the keyboard).This is what I did to get the output
shown below:
@% = 4
152 446 519 344 935 445 495 500 107 633 459 691 406 618 494 445 199
579 774 19
@% = 5
264 834 9 420 800 536
456 189 247 868 340 222 640 721
48 957
418 481 718 479
@% = 8
764 806
626 118 485
933 917 306
309 925
763 995
653 980 848
965 7 718
246 58
@% = 10
952
942 493
286 269
301 322
258
734
524 720
286 864
221 92
341
124
796 813
891
@% = 20
742
749
573
541
727
914
662
606
300
529
62
469
826
793
899
161
339
559
614
712
For example, where @%=10, above, there are seven spaces before the three
digits of 952
where @%=20 there are 17 spaces before the 742 in the first column.
FOR strings the effect is shown by the following:
MODE8:OFF
REPEAT
READ k : PRINT"@% = ";k
PRINT
@%=k
PRINTSTRING$(7,"1234567890")
PRINT"Mary","had","a","little","lamb"'''
UNTIL k=10
DATA 5,8,10
Which gives the output :
@% = 5
1234567890123456789012345678901234567890123456789012345678901234567890
Mary had a little lamb
@% = 8
1234567890123456789012345678901234567890123456789012345678901234567890
Mary had a
little lamb
@% = 10
1234567890123456789012345678901234567890123456789012345678901234567890
Mary had
a little
lamb
Note that here the strings are started at the beginning of the fields, whereas
the numbers were fitted in at the end of the fields.
Next Tutorial
Richard Weston's Homepage