Qbasicnews.com

Full Version: WARNINGS re certain QB instructions
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Many times when we're testing, we come across certain instructions that do not do what we want. What's worse is when they work for most data cases, but fail on other data for no apparent reason. Then we normally write the logic a different way and forget the problem. Let's try to warn our friends here of these weird things that happened to us.

I'll start the ball rolling by issuing a warning about Functional Operators, sometimes called Intrinsic Functions, or just called Functions, such as SQR, LOG, TAN, COS, and others.

Sometimes we derive a real neat way of doing something by using the above functional operators. Here's a few warnings:
1) First read the manual regarding the functional operator to find out what is the precision (integer, single, double) that is used in the calculation.
2) Avoid using multiple Functional Operators in the same statement. Because of the precision accuracy, having them in the same statement could give bad results for certain values of the data.
3) Run a complete test in a sample program using the entire range of data values that you intend using, to make sure that the code using these Functional Operators works in every case.

Another pitfall is using exponentiation. Watch out when you use an explicit value like 2^n. It's assuming its own precision. I had a piece of code that worked every time except for the following value:
Code:
defint a-z
n=7
if  2^n = 128 then print "Yes" else print "no"
The result was no.
I fixed it by placing the 2 in a variable called two, and then did
if two^n = 128 .....
*****
RESTORE is a bit buggy:

Code:
READ a%                 'read first data content
READ b%                           'read second..
RESTORE 0                        'jump to top of data again
READ c%                           'read first data content again
READ d%                           'read second...
PRINT a%; b%; c%; d%    'print out all

0                                        'the dangerous label (RESTORE 0)
DATA 10                             'data content 1
DATA 100                           'data content 2

This wil work fine in the IDE (I think -Untested code)
and read the data two times printing
Quote:10 100 10 100
But you can't compile it as an EXE since
the compiler doesn't accept "RETURN 0"
There are certain things that only work with the compiler if you use a command line switch, like event trapping and possibly RESTORE (I'll check on this as soon as I can get to my own computer)

Did you compiler to an EXE from the IDE or by running BC.EXE directly?

Quote:But you can't compile it as an EXE since
the compiler doesn't accept "RETURN 0"
If you had put the same typo in the BAS file, compiling it would indeed have generated an error on that line... I assume you really mean "RESTORE 0"...
Never use the line number 0!
Probably it is in the printed manual, I don't have it...
Quote:This wil work fine in the IDE (I think -Untested code)

The above comment reminds me of what Donald E. Knuth once said:

"Beware of bugs in the above code;
I have only proved it correct, not tried it."

I love it 'cause it's so true.
*****
Line 0 is used to disable ON ERROR, ON TIMER...., so it should never exist by definition, only the IDE is not programmed to reject it.
Antoni,
What line 0 do you mean? Are people still using line numbers?
*****
If you say something like ON ERROR GOTO 0, the error handler is disabled.