Page 2 of 2

Re: SuperBASIC function for type validation

Posted: Fri Jul 10, 2020 5:30 pm
by pjw
I cant remember whether or not WHEN ERRor is part of SuperBASIC. Q-Liberator has its own variant, as does Turbo.

Personally I prefer my own VALID% toolkit function (naturally):

ok% = VALID%(expected_type%, <variable or expression>)

It uses the standard Qdos calls to try to fetch the variable/expression on the
stack as the type you specify (int, long, float), and returns its success or not
in ok%. The advantage of this method is that its interpretation will be 100%
consistent with the S*BASIC interpreter's idea of a variable's validity.

For example x% = '1e700' is a valid integer! Namely 1. However, x = '1e700' is
not a valid float! It may not be easy to cater for such anomalies in a home-grown
validy-checking program. At least not without WHEN ERRor. Much better to let
S*BASIC do the hard work!

PRINT VALID%(3, '1e700') will return ok
PRINT VALID%(2, '1e700') will return not ok (2 being the code for float)

VALID%, including it source code (so you could, for example, add it to your own
bespoke toolkit) can be found at Knoware.no

Re: SuperBASIC function for type validation

Posted: Fri Jul 10, 2020 5:44 pm
by dex
I cant remember whether or not WHEN ERRor is part of SuperBASIC
QL ROM (post JM)
This SuperBASIC structure does not work very reliably on any QL versions other than Minerva v1.77 (or later), SMS or the THOR XVI: although Toolkit II improves the reliability...
https://superbasic-manual.readthedocs.i ... error.html

Re: SuperBASIC function for type validation

Posted: Sat Jul 11, 2020 11:20 pm
by RWAP
Good to see people are using and quoting from my SuperBASIC / SBASIC Reference Manual :D