About Array SHARED

If you have questions about any aspect of QBasic programming, or would like to help fellow programmers solve their problems, check out this board!

Moderators: Pete, Mods

Post Reply
thinkSJ
Newbie
Posts: 6
Joined: Tue Dec 28, 2010 11:24 pm
Location: NanJing CHINA

About Array SHARED

Post 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~
User avatar
burger2227
Veteran
Posts: 2466
Joined: Mon Aug 21, 2006 12:40 am
Location: Pittsburgh, PA

Post 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
Please acknowledge and thank members who answer your questions!
QB64 is a FREE QBasic compiler for WIN, MAC(OSX) and LINUX : https://www.qb64.org/forum/index.php
Get my Q-Basics demonstrator: https://www.dropbox.com/s/fdmgp91d6h8ps ... s.zip?dl=0
thinkSJ
Newbie
Posts: 6
Joined: Tue Dec 28, 2010 11:24 pm
Location: NanJing CHINA

Post 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)
User avatar
burger2227
Veteran
Posts: 2466
Joined: Mon Aug 21, 2006 12:40 am
Location: Pittsburgh, PA

Post 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
Please acknowledge and thank members who answer your questions!
QB64 is a FREE QBasic compiler for WIN, MAC(OSX) and LINUX : https://www.qb64.org/forum/index.php
Get my Q-Basics demonstrator: https://www.dropbox.com/s/fdmgp91d6h8ps ... s.zip?dl=0
thinkSJ
Newbie
Posts: 6
Joined: Tue Dec 28, 2010 11:24 pm
Location: NanJing CHINA

Post 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:
Post Reply