Qbasicnews.com

Full Version: Yet another Module question...
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Alright, I can share non-arrayed variables (X,Y, and Z) just fine. I have an include file with the "Common Shared" statements, and it works perfectly.

But how do I get arrays like "Sprite(36,43)" shared throughout all of the modules? I hope I explained that right... thanks.
DIM SHARED in a bi file.
Didn't work... it's "5" in one module... "0" in the other...
blah.bi:
Code:
COMMON SHARED myArray() AS DOUBLE

...

blah.bas (main module):
Code:
'$INCLUDE:'blah.bi'

DIM SHARED myArray(234 TO 3453, 43 TO 456) AS DOUBLE

...

blah2.bas (secondary module):
Code:
'$INCLUDE:'blah.bi'

' No need for a DIM SHARED

PRINT "asdf" ' this line of source code will never be executed

... (SUBs, FUNCTIONs)

You could put a DIM SHARED in blah2.bas if you really wanted to, but it wouldn't do anything... just like the PRINT statement in blah2.bas. Module-level (outside of any SUB/FUNCTION) executable statements (like PRINT or DIM, not like DEFINT or COMMON) are ignored unless they're in the main module.
I did that, and now in the MAIN module, it's telling me "array already dimensioned"... GAAAAH!
hey megaman, what you can do is just make yourself a program that copies together two programs (gets rid of the DECLAREs and puts them all at the front, too).... or use plasma's routines... (dunno where they actually are)
Quote:I did that, and now in the MAIN module, it's telling me "array already dimensioned"... GAAAAH!
Make absolutely sure there is only one (1) DIM for that array in the entire project. It's only the COMMON SHAREDs that should be in all the bas files, or just in the bi.

Quote:hey megaman, what you can do is just make yourself a program that copies together two programs (gets rid of the DECLAREs and puts them all at the front, too)....
Open QB, Click File->Merge...
oh.......
Did it, now I'm getting "Duplicate Definition"... *growl*
Do it like this...

blah.bi:

Code:
COMMON SHARED map() AS STRING * 1

REDIM SHARED map(50, 50, 2) AS STRING * 1

blah.bas:

Code:
REM $INCLUDE: 'blah.bi'

You have to 'REDIM' the 'COMMON SHARED' array in every module. So you can just put the REDIM into the bi file and you get it.