Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

i was just wondering 1

Status
Not open for further replies.

qbasicking

Programmer
Aug 19, 2001
628
US
I was just wondering what kind of commands or string of commands would make a severe error when you one tries to compile it. I just wanna know what to staty away from.
 
Are you kidding me? 1015 member to the Qbasic forum and no one has a clue about what makes a severe error?
 
The one reason for all errors - programmer.
Any error - result of incorrecty progammed reaction on unexpected data flow. :)
So, stay away from any data, all calculations and do not perform branches in programs.
Even program:
PRINT"2*2"
can give unpredictable answer.
So better(not best!) will:
PRINT"4"
PRINT"WHAT NUMBER YOU SEE?"
INPUT A
PRINT"WHAT IS THE ANSWER FOR 2*2?"
INPUT B
IF A<>B THEN PRINT&quot;THERE WAS AN ERROR!&quot;

Keep in mind - it's hard seriosly answer to unseriosly question! ;-)
 
There are several listed in Microsoft QuickBASIC Modern Programming System copyright 1988, 1990.

It starts off with:

Advanced feature unavailable (ERR 73)([red]Compile-time Error[/red])

and ends with:

Wrong number of dimensions
(no ERR number-but is a [red]Compile-time Error[/red])

In my book, these &quot;errors list&quot; start on page 393 and end at page 420. A total of 27 pages of errors listed <in small typeset probably in Pica -- thank goodness it wasn't Elite LOL>.

This includes &quot;invocations, compile-time, and run-time&quot; errors. Any one in particular you are looking for?

--MiggyD It's better to have two heads to solve a problem from different angles than to have tunnel vision to a dead end.
 
I was looking for compiling errors. I have built programs that have run flawlessly in .bas form, but wouldn't compile for it had a few severe errors in it.
 
But... It is not special &quot;compiling&quot; errors. Just ordinal errors which &quot;show yourelf&quot; only after compilation. Or, may be it's non-ordinal programs (with machine-code functions, direct memory addressing instead using variables names, operating system functions(interrupts) calls and so on). Can you tell some more about your errors and programs?
Which compiler you use? What interpreter programs wrote for?
Which code fragments made an errors?
 
There are two things that spring to mind when you mention code that works in the IDE but does not compile.

The first is arrays: the IDE will allow you to use undeclared arrays. It will impose a default dimension of [tt](0 TO 10)[/tt]. However, the compiler makes no such allowance. You must explicitly declare all arrays using [tt]DIM[/tt] statements as follows:
[tt]
DIM myArray%(0 TO 10)
[/tt]
Strictly speaking, the lower bound does not need to be specified. It will default to 0 unless you use [tt]OPTION BASE 1[/tt], in which case it will default to 1. However, it is because of exactly this that I believe it is a good coding practice to always specify the lower bound for arrays. Especially if you are worried about generating errors.

The other thing that springs to mind is also arrays. By default, all data items are &quot;static&quot;, which means that they are preallocated from the data segment before your program runs. The addresses are then stored inside the executable file. The data segment, however, has a limited size -- much more limited than the memory available for variables inside the IDE. If you use large arrays and/or many of them, the compiler may run out of space to put things. You can make the compiler output code that allocates memory the same way that the IDE does by putting the following line of code at the top of your program:
[tt]
'$DYNAMIC
[/tt]
On a similar note, if your program is exceedingly large, there can also be too much code to fit into the code segment. Your program gets one code segment per module. This means that you can break your program up into multiple modules to get more memory for code. To do this, look into the &quot;Create File&quot;, &quot;Load File&quot; and &quot;Unload File&quot; items in the &quot;File&quot; menu of QuickBASIC. They allow you to make a project that consists of multiple .BAS files. Be warned, though: I have found data sharing through the use of [tt]COMMON SHARED[/tt] variables to be very flaky in practice. When I make such large projects, I rely only on parameters to functions.
 
Another curious question: How come Qbasic doesn't allow DATA statements in a SUB?

logiclrd: thanks for clearing that up for me, your post was what I was looking for
 
I don't know why. Probably just because it would be an added complexity that they did not want to deal with. However, you can still group [tt]DATA[/tt] statements for use by a sub using a label and the [tt]RESTORE[/tt] statement. Example:
[tt]
SUB readData1
RESTORE readData1Data
READ numItems%
FOR i% = 1 TO numItems%
READ a%
PRINT a%
NEXT i%
END SUB

SUB
readData2
RESTORE readData2Data
READ numItems%
FOR i% = 1 TO numItems%
READ a%
PRINT a% * a%
NEXT i%
END SUB

'Main program: call the subroutines
readData1

readData2

readData1Data:
DATA 3
DATA 1, 2, 3

readData2Data:
DATA 5
DATA 2, 4, 6, 5, 7
[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top