library

I have tried to use the library feature and keep getting error messages. for example:

PROGRAM test
LIBRARY "csagraphics"
DECLARE draw_axes
CALL draw_axes(1,4,2,5)
END

with

external
SUB draw_axes(xmin,xmax,ymin,ymax)
let ntick = 10 !# tick marks
let dx = (xmax-xmin)/ntick
let dy = (ymax-ymin)/ntick
SET window xmin-dx, xmax+dx, ymin-dy, ymax+dy
let x0 = max(0,xmin)
let y0 = max(0,ymin)
IF ymin*ymax < 0 then
let y0 = 0
Else
let y0 = ymin
END IF
PLOT lines: xmin,y0;xmax,y0 !x axis
PLOT lines: x0,ymin;x0,ymax !y axis
let tx = .1*dy !size of tick mark
let ty = .1*dx
FOR itick = 0 to ntick
let x = xmin + itick*dx
plot LINES: X,Y0-TX; X,Y0+TX
let y = ymin + itick*dy
plot lines: x0-ty,y; x0+ty,y
Next itick
END SUB

error 2:3:9: illegal keyword

what am I doing wrong?

johnlb

Comments

Re: library ...

johnib ... The program code below demonstrates the simplicity of using Library "graphlib.tru", which comes in virtually every edition of True BASIC. The attached program plots the 9th-order Chebyshev polynomial, which approximates "zero" over the interval y = 0, across the interval from x = -1 to x = +1.

There is no documentation for library graphlib, but one can examine its program listing and learn to use it by experimentation; its relatively easy. Regards ... Tom M


! Filename: 9th-order_cheby.tru, tjm, 20060419

LIBRARY "graphlib.tru"
DECLARE DEF f

LET a=1.05
CALL fplot(-a,a)
CALL frame
CALL axes
LET tk=f(a)

CALL ticks(.1*a,.1*tk)
PLOT TEXT, AT .1*a, .8*tk: "File: 9th-order_cheby.tru"
PLOT TEXT, AT .1*a, .7*tk: "By: tjm, 2006-04-19"
PLOT TEXT, AT .1*a, .6*tk: "DEF f(x)=256*x^9-576*x^7+432*x^5-120*x^3+9*x"
PLOT TEXT, AT .1*a, .5*tk: "X tick spacing = " & str$(.1*a)
PLOT TEXT, AT .1*a, .4*tk: "Y tick spacing = " & str$(.1*tk)
END

illegal keywords

Hi,

You need to be careful about using the word PROGRAM.
Try putting a REM: statement in front of PROGRAM otherwise TB will expect a your program to supplied with an argument for the variable "test".

Big John

Library

It worked when I added the word sub to this line


DECLARE sub draw_axes

re:library

Your library file needs to be either a *.trc or *.tru file and be called as such. You may also need to give the complete path for the file unless it is in the same folder as your program of you have an alias setup for the library folder.

rwt