Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Where is the return value? (solved but with exit error)
#1
LET s$ = "1+1"
LET s$ = CHR$(_VAL) + """" + s$ + """"
LET r = EvalBasic(s$)

How do I get the return value of VAL ?
Reply
#2
#include <basic.bas>

#define _LET 241
#define _VAL 176

LET exp$ = "3/4"
PRINT exp$;"= ?"
LET s$ = CHR$(_LET, CODE "r",CODE "=",_VAL)
LET s$ = s$ + """" + exp$ + """"
EvalBasic(s$)

LET vars = PEEK 23627+256*PEEK 23628 ' 23799
IF vars <> 23799 THEN PRINT "Error: Vars addr at ";vars

DIM w AS FLOAT AT 23799+1
PRINT CHR$(PEEK 23799);"= ";w


Output:
r= 0.75

This works but when program exits I got this error message:
? ?E, 30:1
Reply
#3
I gave up using EvalBASIC and, with a few tricks, I managed to use VAL like on the ZX Spectrum.

Like:

s$ = INPUT(32) ' example: "SIN(x*10)+5/(1+x*x)"
s$ = FixExpression(s$)
y = VAL s$
Reply
#4
Sorry, the forum is (again) under severe spam attack. :-(

I understand that FixExpression converts SIN to its token?
Reply
#5
Yes, convert SIN to its token and convert x to its value.
Reply
#6
ZX Basic VAL calls ROM's VAL which in turns evaluates complex (BASIC) expressions.
The corruption message you show above also happened to me in 128K mode, but not in 48K mode...
Which mode did you use?
Reply
#7
48K .
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)