Page 1 of 1

About Array SHARED

Posted: Tue Jan 11, 2011 10:43 am
by thinkSJ
Hi, all :D
There is a new problem in my project:
How to access an array in other BAS file?
eg: In a.bas has following code

Code: Select all

      DIM SHARED test(10)    AS LONG
And i want to access this array in b.bas, How to do that?

Thanks for your helping~

Posted: Tue Jan 11, 2011 12:35 pm
by burger2227
That depends on how you get from A to B. I assume you are running them consecutively. Why do you need 2 modules? Too big?

If you CHAIN to B then use a COMMON list with the array included. The lists must be identical in both modules. CHAIN does not require the BAS or EXE extension, but both modules must be the same type to work.

CHAIN compiled EXE file programs will need BRUN45.EXE too. That is the default setting when you compile. Just include it with the program when sharing.

Ted

Posted: Tue Jan 11, 2011 2:14 pm
by thinkSJ
Hi Ted:

Thanks for reply~! The project include 30 BAS files.
My IDE is Qbasic7.1. BRUN45.EXE is not exist in that folder.

I still dont know what shoud i do~ would you mail me a test project?

http://www.eng.umd.edu/~nsw/ench250/qbasic.htm
Here has a method to share an array, but not consort for me~

Code: Select all

  ex. Share an array
        common shared x(), y()
        n=5.
        dim x(n), y(n)

Posted: Tue Jan 11, 2011 2:53 pm
by burger2227
I don't know how PDS does it. Look in the help file, but I didn't see anything about needing anything with it. Probably uses better memory management too.

The common list goes by the variable TYPE not the name so each list must match:

Module1: COMMON first$, sec%, third!, forth#, fifth%()

Module2: COMMON sec$, forth%, first!, third#, last%()

Arrays don't need the number of elements. You can use COMMON SHARED if SUB procedures use them INSIDE of the module too.

To use CHAIN to go from ModuleA to B:

CHAIN "ModuleB"

It should keep the same screen mode and the COMMON values should work.

Just make two test modules and set the COMMON values in the first one and print them in the second one.

Ted

Posted: Wed Jan 12, 2011 1:24 am
by thinkSJ
Hi Ted: Thanks~Problem is resolved.
CHAIN can share an array's buffer

In Qbasic, an array include a buffer for storage data and a mangement struct to manage this buffer~ eg:

Code: Select all

ManStruct 
    dd  pDataBuf
    dw ...
    dw ...
    db 1
    db ...
    dw  Offset pDataBuf
    dw 2
    dw 4
    dw 0
.........
pDataBuf db 8 dup(0)
That link's method can share ManStruct ,pDataBuf and let BC generate
B$DDIM call.
CHAIN just share pDataBuf, that's what i need, thanks again~:lol: