J.E.Lawrie                                                    HINTS-15.


ODD JOTTINGS AND REMINDERS ON BASIC

ABBREVIATIONS           To check that the printer is ready, include
                          IF GET(&E5) AND 1 THEN .......
CHAIN     CH.
CLEAR     CL.           To print what is coming on the screen, include
DELETE    DEL.            OSCLI("CLI #+P~E"):dummy= INKEY(0)
ENDPROC   E.              ( not necessary to use "#-P" to switch off )
INPUT     I.
LIST      L.            To delete a file from RAM
LOAD      LO.              *ERASE filename   or :*//filename
NEXT      N.            (Use OSCLI if filename is a string variable)
PRINT     P.
RENUMBER  REN.          To go to the Index when in Basic, using TAB key
RETURN    R.            IF INKEY(0)=9 THEN OSCLI("CLI #I"):dummy=INKEY(0)
STEP      S.
LEFT$     LE.           To empty the keyboard buffer
RIGHT$    RI.             REPEAT UNTIL INKEY(0)=-1
MID$      M.
FALSE     £             To hold at a line until a particular key is pressed
                          REPEAT UNTIL GET=32 (spacebar in this example)
                                      or  =CHR$(X)

                        To abort a program -  reverts to the index
                          K=INKEY(secs*100):IF K=-1 OSCLI("CLI #I")

  To move graphics on screen, with limits to the movement.
110 KEY=INKEY(0)
120 Y=Y-(1 AND KEY=225 AND Y>0)+(1 AND KEY=254 AND Y<7) for movement of
130 X=X+(1 AND KEY=253 AND X<85)-(1 AND KEY=252 AND X>5) graphics with
                                                        the arrow keys
                                                        -within limits.

33  !       53  5       73  I       93   ]      113  q      9   TAB
34  "       54  6       74  J       94   ^      114  r      13  ENTER
35  #       55  7       75  K       95   _      115  s      32  SPACE
36  $       56  8       76  L       96   `      116  t
37  %       57  9       77  M       97   a      117  u      252  LEFT
38  &       58  :       78  N       98   b      118  v           ARROW
39  '       59  ;       79  O       99   c      119  w      253  RIGHT
40  (       60  <       80  P       100  d      120  x           ARROW
41  )       61  =       81  Q       101  e      121  y      254  DOWN
42  *       62  >       82  R       102  f      122  z           ARROW
43  +       63  ?       83  S       103  g      123  {      255  UP
44  ,       64  @       84  T       104  h      124  |           ARROW
45  -       65  A       85  U       105  i      125  }
46  .       66  B       86  V       106  j      126  ~
47  /       67  C       87  W       107  k      127  (black square)
48  0       68  D       88  X       108  l
49  1       69  E       89  Y       109  m      160  ( hard space )
50  2       70  F       90  Z       110  n
51  3       71  G       91  [       111  o      163  £
52  4       72  H       92  `       112  p

            IF F THEN ...  is the same as IF F<>0 THEN ...


Error trapping

  ON ERROR:dummy=INKEY(0):PROCerr:PRINT:REPORT:PRINT" in line ";ERL:END

    a)   DEFPROCerr:IF ERR=17 .............. ENDPROC ELSE  ...........
or  b)   DEFPROCerr:VDU1,127,1,67,1,83:@%=&0002000A:ENDPROC

    a)  allows a deliberate escape from the program.  Other errors
        will not stop the program ( but it cannot carry on from
         where the error occurred!).
    b)  stops the program after restoring the VDUs and print format.


Use of INSTR
            110 REPEAT
            120  A$=GET$
            130  A= INSTR("1122334455667788=+.>IiAaDdSs  Qq",A$)
            140 UNTIL A>0

            A keypress for A$ is checked against the contents of INSTR.
            If a match is found then A returns a figure - in this case
            from 1 to 32 else A=0

            150 A=INT((A+1)/2) i.e in this example A can be from 1 - 16
                                   ( it allows upper and lower case ).
            160 IF..
            170 IF..

            180 A=A-10:ON A GOTO 210,260,310 etc etc 850
                        (850 could be QUIT, matching Qq)


Print Format
            Default print format instruction is  @%=&90A which gives a
            format of 9 digits in a field width of 10.

            My preference is  @%=&2000A  to avoid decimals
            or  @%=&2020A  to give two decimal places in a width of 10


Channel Error
            In programs where a second attempt to open a channel
            results in an error i.e CN has a positive value, use
                  IF CN<>0 (file is already open) THEN .......

            Put this immediately after  CN=OPENIN(" datafile ")

OSCLI Strings
            Example -
            110 b$=a$(J)
            120 INPUT "RAM ?"R$
            130 OSCLI("CLI #F|SV~D:RAM."+R$+"|EF"+b$+"~E~E|[")

            Which means "go to the Filer,:RAM.(R$), and fetch from
            EPROM the file  b$)

            All entries in the OSCLI must be in arrays.


LINE EDITOR

            If the C.C.L line editor is saved as a file called LINEDIT
            it can be added to the listing of a Basic program with the
            command   *CLI .*:*//LINEDIT


Carrying variables or numeric values within Basic

            110 PROCshift(10)  or  PROCshift("TEN")
            120 X$="SIX"
            130 X=6
            140 X$="FORTY"
            150 X=40
            ...
            300 DEFPROCshift(X)       X will now be 10
         or 300 DEFPROCshift(X$)     X$ will now be TEN


IF F THEN ... means " IF F<>0 THEN ......


Logic Operators

            a)   U=U-(G=0)  If G=0 this expression = -1 otherwise = 0
                            so, if G=0 then  U=U+1 else U is unchanged.

            b)   U=U+6*(U=6) If U=6 it reduces the value by 6 otherwise
                             U is unchanged.  Can be used when U is
                             increasing but at 6 it reverts to zero.

            c)   TAB(X+(R>9),0);R  If R>9 it will appear on the screen
                                   one space earlier.

            8                                       8
            9   is normal.  Using the above we get  9
            10                                     10


Basic       11 DIV 4 = 2  (the whole No.)
Maths       11 MOD 4 = 3  (the remainder)

            RND(x) gives random Integers from 1 to x
            RND(1) gives a number from 0 to .99999999....

            TRUE is -1
            FALSE is 0

            PI = 3.1416....     EXP = 2.7183....

            LN is the Natural Log of x, to the base e
            LOG(x) is the Common Log,   to the base 10

            TAN(RAD(x)) gives the Tangent of x degrees
            Y=RAD(X)*180/PI converts x radians to Y deg.
                                                                    END

Back to HINTS-INDEX