VALID
                                    =====

Test whether a variable is valid as a given type


Usage:
------

        RETurn VALID%(expected_type, variable)

where expected_type is:

        0 = long integer, 1 = string, 2 = floating point, 3 = integer.

A further type exists: -1 = query

If the variable, literal or expression does not conform to the expected
type the function returns zero, otherwise it returns non-zero. An
additional bonus of this function is that it returns zero if the variable
is unset ie, has not been given any value. (This is not true for the
SMSQ/E version of SuperBASIC, SBASIC, though. But then it doesn't fall
over when it hits an unset variable either).

This makes it possible to write procedures in SuperBasic with optional
parameters, eg

        DEFine PROCedure Test(a$,b,c%)
        IF NOT VALID(3,c%):c%=default%
        PRINT a$,b,c%
        END DEFine

Set default% to whatever you like and try

        Test '1',2

or
        Test 1,2,3

or
        Test '1',2,'rubbish'.

(SBASIC requires a slight modification).


A variation on VALID is query:

        RETurn VALID%(-1, variable)

returns the type of the parameter variable as an integer. It does not tell
you whether the contents of a variable are valid or not eg whether
a$='.-3' is a valid number, as you can using the other type specifications
above, but it will tell you the basic type of the variable in question.
These are the types that can be tested (values in hex and decimal):

$0001 (1) unset str   $0201 (513) set str   $0301 (769) str array
$0002 (2) unset fp    $0202 (514) set fp    $0302 (770) fp  array
$0003 (3) unset int   $0203 (515) set int   $0303 (771) int array

also:

$0602 (1538) REPeat loop index   $0702 (1794) FOR loop index
$0300 (0768) Sub string

You can also tell which separator (ie , ; ! \ TO) variable is followed by,
or whether it is preceded by a hash -

        PRINT VALID(-1,#2;)

but what's the point?


Software status:
----------------

Two versions of VALID are included here:

One compact, all-inclusive toolkit, VALIDi ( _BIN and _asm), as per the
article on Knoware. Use this toolkit if the function is to be used on its own.

The second version has been "modularised" so it can easily be made part of
a pick 'n mix toolkit. It appears bulkier, as it uses libraries for routines
that may be common to many different commands.


V0.01, © PWITTE, 1992
V0.02, pjw, June 23rd 2000, bug fix
V0.03, pjw, June 20th 2019, All platforms (two formats)

Conditions of use and disclaimer as per Knoware.no