QL VAL String Function

Author(s): Robert Hartung
Publication: The Data Expansion
Pub Details: The Data Expansion v5 n3 (Volume 5, Issue 3)
Date: March 1988
Pages: 15-16

Vol.4, No.2, TDM, Pg. 32

A long time ago I saw a note by Mike de Sosa on the lack of the VAL sting finction on the QL. At the time I didn’t have one, but witih the recent price cuts I’ve added a QL to my “home for orphan computers”. Although I ordered one with software and QL User Guide, it came sans manual (later received), so I was digging through all my old Sinclair mags for info when I ran across Mike’s comment again.

No doubt other users have found purely software approaches since then, although I have found no one published ones in my non-QL specific mags except the one Mike gave which utilizes Microdrive commands. The problem seems to be that while SuperBASIC does correctly interpret the value of an expression discretely entered as a program line, for example:

LET a$=2^3*PI or LET a=2^2*PI/C

It seems to “see” only the first item (2) if the same expression is entered in response to INPUT a:

LET a$=a: PRINT a$/C

While it is a clumsy substitute for what can be done so routinely with “lowly” TS1000/2068 BASIC, the following process will give the correct output for an expression entered as the definition of either a numeric variable or as a string variable definition without quotes or asterisks:

10 expr=0: REM or expr$=0
20 WHEN ERROR
30 RETRY
40 END WHEN
50 CLS: CLS #0: PRINT "expr = ";expr: PRINT "Enter expression, the r for result": EFIT 10: STOP
60 DEFine PROCedure r
70 RUN
80 END DEFine r