2000 REM ********************* 2010 REM PRIMER - First Steps 2020 REM ********************* 2030 DEF FN posn$(x,y)=CHR$(27)+"Y"+CHR$(32+y)+CHR$(32+x): REM position cursor 2100 filename$="PRIMER":PRINT cls$:PRINT TAB(15)rvson$" "rvsoff$ 2110 PRINT TAB(15)rvson$" BASTUTOR PRIMER - First steps in Mallard Basic "rvsoff$:PRINT :PRINT 2120 PRINT " In this section of the course we are going to look at the most fundamental and essential parts of programming in BASIC. The headings below will give you some idea of what is covered " 2130 PRINT " You can either work straight through the sections in order as they come up, which is recommended, or you can go straight to any section by typing it's reference letter" 2140 PRINT:PRINT TAB(25) "a) Printing to the screen" 2150 PRINT:PRINT TAB(25) "b) Working with numbers- simple maths" 2160 PRINT:PRINT TAB(25) "c) Variables " 2170 PRINT:PRINT TAB(25) "d) Loops - play it again, Sam" 2180 PRINT:PRINT TAB(25) "e) Input from the keyboard " 2190 PRINT:PRINT TAB(25) "f) Strings -'n things " 2200 PRINT:PRINT TAB(25) "g) How to clear the screen -intro to codes" 2205 PRINT:PRINT TAB(25) "h) INDEX " 2210 PRINT:PRINT TAB(25) "i) Return to Main Menu 2215 PRINT rvson$ FN posn$(15,30) SPC(55) rvsoff$ 2217 PRINT rvson$ FN posn$(17,30) "Please press the letter of the section you require" rvsoff$ 2220 PRINT: PRINT 2230 select$=INKEY$ 2240 IF select$="" THEN 2230 2250 code = INSTR(1,"aAbBcCdDeEfFgGhHiI",select$) 2260 IF code = 0 THEN PRINT "Please press a letter key a,b,c,d,e,f,g,h, or i":GOTO 2230 2270 ON code GOTO 4000,4000,6000,6000,8000,8000,10000,10000,12000,12000,14000,14000,16000,16000,18000,18000,10,10 4000 GOSUB 40050 4100 PRINT cls$:TYPE PRIMER.A 4110 GOSUB 40150 4115 ON code GOTO 4120,4120,4000,4000,2000,2000 4120 PRINT cls$:LIST 4150-4240 4140 PRINT cls$ 4150 PRINT " All characters between double quote marks print exactly as typed" 4155 ' 4160 PRINT:PRINT" Note that the first PRINT makes a blank line [4160]" 4165 ' 4170 PRINT:PRINT" Note also the colon : is used to separate instructions [4170]" 4175 ' 4180 PRINT:PRINT 8256; :PRINT" - Pure numbers need no quote marks [4180]" 4185 ' 4190 PRINT:PRINT 3+4 ;:PRINT" - The answer to the sum 3+4 is printed [4190]" 4200 PRINT:PRINT " 3+4= "3+4;: PRINT " - a simple excursion into maths DISPLAY [4200]" 4210 ' 4220 ' **************************************************************************** 4230 ' * To see how this listing looks when run, type GOTO 4150 then press RETURN * 4240 ' **************************************************************************** 4250 PRINT:GOSUB 40100 4320 PRINT cls$:ZONE(15):LIST 4350-4450 4350 PRINT TAB(15) "The TAB function is used to indent a line [4350]" 4360 PRINT TAB(20) "See how the number varies the distance from the side [4360]" 4370 PRINT TAB(5)" Sometimes easier than using leading spaces [4370]" 4380 PRINT:PRINT TAB(50)"It doesn't work if TAB no.is too large for the text line;[4380]" 4385 ' 4390 PRINT:PRINT"Lets look at zone printing [4390]":REM note the commas between the items 4400 PRINT:PRINT 1,2,3,4,5,6 4410 PRINT:PRINT "TED","KATE","ROBERT","SIAN","THOMAS","CATHERINE" 4420 ' 4430 ' ************************************************************************** 4440 ' *To see how this listing looks when run type GOTO 4350 then press RETURN* 4450 ' ************************************************************************** 4460 PRINT:PRINT" What happens if we remove the commas in lines 4400 & 4410 ?" 4490 GOSUB 40100 :PRINT cls$ 4520 LIST 4550-4660 4550 PRINT 1,2,3,4,5,6 : REM Zone printing - in absence of other instruction zone number is 15 4570 ZONE(18):PRINT 1,2,3,4,5 4580 ZONE(30):PRINT 1,2,3 : REM Do you see?. The number varies the spacing. 4590 ZONE(15) : REM This returns spacing to default value. 4600 PRINT:PRINT "I hope that you are"; 4610 PRINT " enjoying the course so far"; 4620 PRINT " and are doing some experimenting" 4630 ' : Note the semi-colons after lines 4600 &4610. They will force the three lines 4600,4610,and 4620 to print on one line. 4640 REM 4645 REM ************************************************************************ 4650 REM *To see how this listing looks when run type GOTO 4550 then press return* 4655 REM ************************************************************************ 4660 PRINT 4690 PRINT:PRINT" Try varying the zone numbers. What happens when you add more numbers" 4700 PRINT" to lines 4550,4570, or 4580 ? If you print these lines all with the" 4710 PRINT" the same zone number you will print in columns. You can zone print " 4720 PRINT" with text in the same way.Useful for making lists? " 4800 GOSUB 40100 :PRINT cls$: LIST 4820-5015 4810 PRINT:GOSUB 40100 4820 PRINT TAB(15)"**** LISTING SHOWING ALL PRINT COMMANDS COVERED SO FAR ****" 4830 PRINT: 4840 PRINT " LIST OF PERSONNEL - " 4850 PRINT:ZONE(30): PRINT "NAME","CODE NO.","FUNCTION" 4860 PRINT " _____________________________________________________________________" 4870 PRINT:PRINT "Bond, James"," 007", "Licenced to kill" 4880 PRINT "Rover"," K9" , "Licenced to bite" 4890 PRINT "Mlle Fifi", " 38-24-38" ,"Unarmed combat " 4900 PRINT "Dr Jekyll", 99 ,"Disguises" 4910 PRINT "A.Coward"," B4U","Personal survival" 4920 PRINT "Nelson"," 1I","Lookout" 4950 PRINT:PRINT TAB(10)"All personnel will meet at 1800 hrs. 8/23/88 in the snug bar"; 4960 PRINT "of 'The Dying Duck' public house to be addressed by Colonel Z. Z must remain"; 4970 PRINT "incognito, but to make himself recognisable will wear a paper bag over his "; 4980 PRINT "head, printed with the words ' British Intelligence Agent'" 4990 PRINT:PRINT "AGENDA":PRINT "1) Minutes of last meeting":PRINT "2) Talk by Z on serious shortage of paper bags":PRINT"3) Demonstration by K9 of bare teeth biting":PRINT"4) Collection to pay for new bottom set for K9 " 5000 PRINT " (damaged by boot of 007 after last demonstration.)":PRINT "5) Any other business ": PRINT "6) Meeting ends:- just before Z's round" 5001 ' 5005 REM ****************************************************************** 5010 REM * To see how this listing runs type GOTO 4820 then press RETURN * 5015 REM ****************************************************************** 5020 PRINT "*******************************************************************" 5030 GOSUB 40100 5040 PRINT cls$: 5500 PRINT cls$:PRINT TAB(20) " You now have the following options " 5510 PRINT: PRINT " Reread the text.......................... " TAB(50) "type GOTO 4000" 5520 PRINT: PRINT " List the 1st section on PRINT ........... " TAB(50) "type GOTO 4120" 5530 PRINT: PRINT " Run ------------------ PRINT ........... " TAB(50) "type GOTO 4140" 5540 PRINT: PRINT " List the 2nd section on PRINT TAB( )..... " TAB(50) "type GOTO 4320" 5550 PRINT: PRINT " Run ------------------ PRINT TAB( )..... " TAB(50) "type GOTO 4350" 5560 PRINT: PRINT " List the 3rd section on ZONE ............ " TAB(50) "type GOTO 4520" 5570 PRINT: PRINT " Run ------------------ ZONE ............ " TAB(50) "type GOTO 4550 5580 PRINT: PRINT " List the 4th section on commands to date " TAB(50) "type GOTO 4800" 5590 PRINT :GOSUB 40000 5592 GOSUB 40150 : ON code GOTO 6000,6000,4100,4100,2000,2000 6000 GOSUB 40050 6100 PRINT cls$:TYPE PRIMER.B 6110 GOSUB 40160 6115 ON code GOTO 6120,6120,6000,6000,2000,2000 6120 PRINT cls$: LIST 6150-6260 6150 PRINT "24+20 = " 24+20 :REM Simple addition 6160 PRINT "23-14 = " 23-14 :REM Simple subtraction 6170 PRINT "45/5 = " 45/5 :REM Simple division ; note the operator used'/' 6180 PRINT "47x6 = " 47*6 :REM Simple multiplication ; note the operator used '*' 6185 ' 6190 PRINT:PRINT "3x4-2 = " 3*4-2 :REM multiple and mixed calculations 6200 PRINT "12.45/2.453= " 12.45/2.453 :REM Decimals can be used 6210 PRINT "(3+4)x3 = " (3+4)*3 :REM Normal maths protocol applies 6215 ' 6220 PRINT "6480 x 3420= " 6480*3420 :REM Larger nos. are given in E notation 6230 PRINT "2/76 = " 2/76 :REM and so are small numbers. 6240 REM *************************************************************************** 6250 REM * To see how this listing looks when run type goto 6150 then press return * 6260 REM *************************************************************************** 6280 PRINT:GOSUB 40100 8000 GOSUB 40050 8100 PRINT cls$:TYPE PRIMER.C 8110 GOSUB 40160 8115 ON code GOTO 8120,8120,8000,8000,2000,2000 8120 PRINT cls$: LIST 8150-8280 8150 REM === Let us make up some examples of variables === 8160 a=3: b=5: cc=8: age=16: z1=19.5: z2=7 :REM These are examples of numeric variables 8170 a$="Albert": age$="16 yrs": z2$="007" : REM These are examples of string variables 8180 title$= "'Cat on a hot tin roof'": author$= " Tennessee Williams" 8190 PRINT TAB(20) "a+b+cc=" a+b+cc " [ line 8190 ] 8200 PRINT:PRINT author$ " wrote " title$ " [ line 8200 ] 8210 a%=8 : b%=8.2: z1%=z1: REM examples of integer variables. Note how b% and z1% are 8220 : REM - rounded to the nearest whole number 8230 PRINT:PRINT a%;b%z1%, "[ line 8230 ]" 8240 PRINT:PRINT a$ " is " age " or rather " age$ " [ line 8240 ]" 8260 REM ********************************************************* 8270 REM * To see how this listing looks when run type GOTO 8150 * 8280 REM ********************************************************* 8300 PRINT:PRINT "Make sure that you understand the use of the three types of variable" 8310 PRINT "1) String variable with $ suffix 8315 PRINT "2) Numeric variable with no suffix" 8320 PRINT "3) Integer variable with % suffix" 8330 PRINT " Now alter the values of the variables and invent different variables " 8350 PRINT:GOSUB 40100 10000 GOSUB 40050 10100 PRINT cls$:TYPE PRIMER.D 10110 GOSUB 40160 10115 ON code GOTO 10120,10120,10000,10000,2000,2000 10120 PRINT cls$:LIST 10150-10520 10150 PRINT "Example 1 :-";: FOR A=1 TO 20:PRINT A;:NEXT 10155 ' 10160 PRINT "Example 2 :-";: FOR y=0 TO 55 STEP 3:PRINT y;:NEXT 10165 ' 10170 PRINT "Example 3 :-";: FOR x=3 TO 20 : PRINT 7*x ;:NEXT 10175 ' 10180 FOR Z= 0 TO 2500:NEXT : REM Time delay ; delay depends upon numbers to be counted 10185 ' 10190 PRINT "Example 4 :-";: FOR k=100 TO 10 STEP -5:PRINT k ;:NEXT 10195 ' 10200 PRINT "Example 5 :-";:FOR x=3 TO 8 :PRINT "Hello ";:NEXT 10205 ' 10500 REM ********************************************************************** 10510 REM ******* To see how this listing looks when run type GOTO 10150 ******* 10520 REM ********************************************************************** 12000 GOSUB 40050 12100 PRINT cls$:TYPE PRIMER.E 12110 GOSUB 40160 12115 ON code GOTO 12120,12120,12000,12000,2000,2000 12120 PRINT cls$:LIST 12150-12280 12150 INPUT "What is your name "; name$ 12160 INPUT "Who is the most intelligent person you know ? ", int$ 12170 INPUT "Who is the nicest person you know "; nice$ 12180 LINE INPUT "What is your life's ambition "; amb$ 12190 PRINT:PRINT "Well " name$ " I think that you are cleverer than "int$", nicer than "nice$" and you will achieve your life's ambition '" amb$" '" 12200 PRINT :PRINT TAB(30)"Press any key to continue" 12210 WHILE INKEY$="": WEND 12220 PRINT "When you pressed a key INKEY$ was no longer equal to nowt" 12230 PRINT "and so the WHILE.. WEND loop allowed the prog. to continue" 12260 REM ********************************************************** 12270 REM **** To see how this program runs type GOTO 12150 ******* 12280 REM ********************************************************** 12300 PRINT:GOSUB 40100 14000 GOSUB 40050 14100 PRINT cls$:TYPE PRIMER.F 14105 GOSUB 40160 14115 ON code GOTO 14120,14120,14000,14000,2000,2000 14120 PRINT cls$:LIST 14150-14240 14150 PRINT "Have"" a"" nice" " day" :REM one way to add strings 14160 PRINT "24th." " April" 1988 :REM Numbers need no " " 14165 ' 14170 PRINT: l$="la":a$="a ":l2$="tle ": h$=" had ":m$="Mary": l1$="lit": m1$="mb" 14180 PRINT m$+h$+a$+l1$+l2$+l$+m1$ :REM addition of strings by way of variables 14190 PRINT "The spaces within the quote marks are used to separate words in these examples." 14220 ' **************************************************************************** 14230 ' * To see how this listing looks when run, type GOTO 14150 then press RETURN * 14240 ' **************************************************************************** 14500 PRINT:GOSUB 40100 16000 GOSUB 40050 16100 PRINT cls$:TYPE PRIMER.G 16105 GOSUB 40160 16115 ON code GOTO 16120,16120,16000,16000,2000,2000 16120 PRINT cls$: LIST 16150-16305 16150 PRINT " *** This is a short program to demonstrate the CHR$ function ***" 16160 PRINT "Type any number between 0 and 255 and press RETURN- you will be rewarded " 16170 PRINT "with the corresponding ASCII symbol. When bored type a number greater than" 16180 PRINT "255 and you will go to the next part of the section. Note that numbers from" 16190 PRINT "0 to 32 do not have a visible output. They are control codes. 7 is the Beep" 16200 INPUT " ",c 16210 IF c>255 THEN 16250 16220 PRINT TAB(30) CHR$(27)+"A"; rvson$" " CHR$(c)" "rvsoff$ 16222 REM CHR$(27)+"A" is a cursor control code and causes the cursor to go up a line After line 16200 has printed the number of your choice, line 16220 would normally be printed on the next line down 16223 REM **The Escape code raises it so that your number and the ASCII character print on the same line. 16224 REM ** rvson$ & rvsoff$ turn the reverse video on and off. They are DEFined FunctioN as you will shortly see [ lines 20 and 30 ] 16230 GOTO 16200 16246 ON ERROR GOTO 16245 16250 ' 16265 PRINT "*** This program demonstratesthe ASC function (reverse of CHR$)***" 16270 PRINT "Characters typed from the keyboard reveal their ASCII number" 16275 PRINT "When bored press ! to continue":GOTO 16277 16276 PRINT " I can't respond to special keys - please try again" 16277 ON ERROR GOTO 16276 16280 INPUT " ",y$ 16285 IF y$="!" THEN GOTO 16310 :ELSE 16290 16290 PRINT TAB(30) CHR$(27)+"A"; rvson$" " ASC(y$)" "rvsoff$ 16295 GOTO 16280 16299 REM ************************************************************* 16300 REM * To run this program type GOTO 16150 then press RETURN * 16301 REM ************************************************************* 16310 PRINT: GOSUB 40100 16315 PRINT "And now, take a look at the start of 'TUTOR' showing how some of the codes " 16320 PRINT "are used. These lines remain valid the whole program through, and form the " 16325 PRINT " 'initialisation' module. ( dreadful terminology )" 16330 PRINT:GOSUB 40100:PRINT cls$ 16350 LIST -99 16400 PRINT "We have come to the end of PRIMER; pressing [RETURN] will take you " 16410 PRINT "back to the section menu" 16420 PRINT: GOSUB 40100 : GOTO 2000 18000 PRINT cls$ 18010 PRINT TAB(20)rvson$" "rvsoff$ 18020 PRINT TAB(20)rvson$" INDEX "rvsoff$ 18030 PRINT:PRINT: GOSUB 40050 18040 PRINT cls$: TYPE INDEX.ASC 18050 GOSUB 40150 18060 ON code GOTO 18200,18200,18000,18000,2000,2000 18070 PRINT cls$: PRINT "That is the end of PRIMER ": GOSUB 40100: GOTO 2000 18200 PRINT cls$: PRINT "That is the end of PRIMER ": GOSUB 40100: GOTO 2000 39990 END  of PRIMER ": GOSUB 40100: GOTO 2000 18200 PRINT cls$: PRINT "That is the end of PRIMER ": GOSUB 40100: GOTO 2000 39990 EN