Also, (off subject a bit) in QB 4.5, how do I let it still open/create
files when I compile to exe, and why won't the RUN command by itself
that should just restart the program, work when I try to compile?
Nerd42 wrote:
I don't understand your questions. QuickBasic 4.5 uses the same IDE
(integrated development environment)/Editor that QBasic 1.1 does. You
should be able to work with your programs in 4.5 just like in 1.1 until
you're ready to compile them. However, once you've compiled the program,
then it's just like any other DOS program. You run it from DOS, not from
within QuickBasic.
There are some slight differences between the interpreter and the
compiler, but you're not likely to run into them unless you're doing some
esoteric stuff.
that "$dynamic" compiler directive thingie. What is it? What does it do?
Nerd42 wrote:
> > I don't understand your questions.
>
> that "$dynamic" compiler directive thingie. What is it? What does it do?
Oh, okay. If I recall correctly, a static array is basically an array of
fixed size. Once you declare a static array, you can't change its size.
With a dynamic array, however, you can change its size whenever the program
needs to.
For example, I have a 3D maze program that I wrote inQuickBasic at:
http://macsnafu.freeyellow.com/pcstuff/blindaly.html
I use arrays to store the "walls" of the maze, but I use dynamic arrays,
because I let the user choose the size of the maze. Only after the user
enters the size of the maze does the program know how big the arrays need to
be. A static array would only work if I simply declared the largest
possible size that a maze could be, which would be a waste of memory if the
user plays smaller mazes, as I imagine most people would. Dynamic arrays
only use as much memory as is necessary for the selected maze.
Hope that helps
>> I don't understand your questions.
>
>that "$dynamic" compiler directive thingie. What is it? What does it do?
Static and Dynamic Arrays
How you declare an array also determines whether it is static
(allocated when the program is translated) or dynamic (allocated
when the program is run):
How array is declared Allocation
------------------------------------------ ----------
Declared first in a COMMON statement Dynamic
Implicitly dimensioned arrays Static
Dimensioned with numeric constants Static
or CONST statement constants
Dimensioned with variables as subscripts Dynamic
Examples of different DIM statements and results:
Statement Result
------------- --------------------------------------------------
DIM A(0 TO 9) Array A is allocated as a static array if
$DYNAMIC is not in effect.
DIM A(MAXDIM) If MAXDIM is defined in a CONST statement, array A
is a static array. If MAXDIM is a variable, then
the array is a dynamic array and is only allocated
when the program reaches the DIM statement.
If the array size exceeds 64K, if the array is not dynamic,
and if the /AH option was not used, BASIC may generate the error
message, "Subscript out of range" or "Array too big." Reduce the
size of the array or make the array dynamic and use the /AH
command-line option.
(and also)
The $STATIC metacommand sets aside storage for arrays during
compilation.
The $DYNAMIC metacommand sets aside storage from arrays while the
program is running.
REM $STATIC
or
' $STATIC
REM $DYNAMIC
or
' $DYNAMIC
Usage Notes
When the $STATIC metacommand is used, the ERASE statement
reinitializes all array values to zero (numeric arrays) or the null
string (string arrays) but does not remove the array.
$DYNAMIC allocates storage for arrays while the program is running.
This means that the ERASE statement removes the array and frees
the memory it took for other uses. You also can use the REDIM
statement to change the size of an array allocated using $DYNAMIC.
The $STATIC and $DYNAMIC metacommands affect all arrays except
implicitly dimensioned arrays (arrays not declared in a DIM
statement). Implicitly dimensioned arrays are always allocated as
if $STATIC had been used.
All arrays inside a SUB or FUNCTION procedure are dynamic unless the
STATIC keyword is included in the SUB or FUNCTION statement.
--
Arargh (at arargh dot com) http://www.arargh.com
To reply by email, change the domain name, and remove the garbage.
(Enteract can keep the spam, they are gone anyway)