Re: (Nearly) solved: FuNction which tests if a variable is set
Posted: Thu Apr 20, 2017 12:00 am
Hi ql_freak,ql_freak wrote:Is there a S(uper)BASIC-function which tests if a variable is set?
Code: Select all
REMark Turbo Toolkit required for END_CMD
IF NOT variableSet(a_%):END_CMD
REMark Alternative: IF NOT variableSet("a_%"):END_CMD
REMark Continue with command file only if a_% is set
REMark ... (your commands)
In SBASIC (SMSQ/E on QPC2) you can use:
IF NOT a_%:END_CMD
But this does unfortunately not (even) work on Minerva It is also not what I want, cause if a_% is 0 the command file will always stop. But perhaps the command file should continue and use the value 0.
I believe there is a slight misunderstanding with how "END_CMD" works. What END_CMD actually does is to close the command file, so that everything is hunky dory with the operating system. It has no effect on command execution, and will not STOP any following commands from continuing. Therefore I can suggest you try placing just one single END_CMD as the first executable command, and replace all other occurrences of END_CMD with STOP.
Agreed, this does do it, yes, but there is an unforeseen forthcoming ... Suppose we have as our currently loaded program ...EDIT:
Found a function from Turbo Toolkit: BASIC_INDEX%(name$) does it. Returns a value <0 if no such name exists.
Now, both x% and y% are genuine names and BASIC_INDEX%() will return there actual index in the SuperBASIC name table, which will be a non negative integer.
Code: Select all
100 x% = 100
110 y% = 100
However, suppose that the program has not been RUN yet! What this means is that both x% and y% will not have obtained any values. If PRINTed, both x% and y% will print out as "*"s, asterisks. There is the need to check for this UNSET status. Jan Bredenbeek has pointed out PARUSE, which I believe will still work outside of procedures and functions. There is also my own suggestion of the UNSET function from DIY toolkit Volume "P".
The above applies only to QDOS. Under SBASIC, x% and y% will have obtained default values of zero.
Perhaps a check is needed to test for version, e.g. IF VERS="JSL1" or IF VER$="HBA", etc.
It is perhaps a question of trial and error, and finding out which will work on your own systems. I personally find programming can be most frustrating even at the best of times. Nothing seems to work, at least at first, it is bug after bug after bug. The most simplest of problems can often turn out to be the most time-consuming. It can take an age to get a program to run as expected. I believe this to be true regardless of the language being used, not just SuperBASIC.