BBS: Inland Empire Archive Date: 11-22-92 (00:30) Number: 380 From: PETE DUDESEK Refer#: NONE To: MICHAEL BAILEY Recvd: NO Subj: Variable Sharing in QB45 Conf: (2) Quik_Bas
> combnations of COMMON SHARED, DIM SHARED, and SHARED statements with
> each of the modules and subs, and the variables still aren't being
> shared back up to the module level and across to other modules.
> Anyone know what I'm doing wrong, or am I trying to handle this
I had the same problem recently and here is how I do it now.
This is a simple little test program for you to use to see how
to pass variables in modules. Just cut each one out and save
them as a seperate files. COMMON.INC, DECLARE.INC, MAIN.BAS,
SUB1.BAS, SUB2.BAS, and SUB3.BAS.
Now load up QB and load in MAIN.BAS. Then with File/Load command
Load in SUB1.BAS, SUB2.BAS and SUB3.BAS.
Now run the program to see it work at passing to and from.
' ----- save this as COMMON.INC --------
' These are all the common shared variables to be used
' by MAIN.BAS, SUB1.BAS, SUB2.BAS, SUB3.BAS
COMMON SHARED Global1$, Global2$, Global3$
COMMON SHARED Global1%, Global2%, Global3%
COMMON SHARED Global4$()
DIM SHARED Global4$(10)
Global1$ = "This is the Global1$"
Global2$ = "This is the Global2$"
Global3$ = "This is the Global3$"
Global1% = 1
Global2% = 2
Global3% = 3
FOR Z% = 1 TO 10
Global4$(Z%) = "This is array Global4$ " + STR$(Z%)
NEXT Z%
'----- End of COMMON.INC -----
'----- Save this as DECLARE.INC -----
' This is the common declare file to be used with
' MAIN.BAS, SUB1.BAS, SUB2.BAS, SUB3.BAS
DECLARE SUB Sub1Sub ()
DECLARE SUB Sub2Sub ()
DECLARE FUNCTION Sub3Function% (Tmp$)
DECLARE FUNCTION Sub3Function4$ (Tmp AS INTEGER)
'----- End of DECLARE.INC -----
'----- Save as MAIN.BAS -----
' This is a simple test program
' This is the main module called MAIN.BAS
' $INCLUDE: 'DECLARE.INC'
' $INCLUDE: 'COMMON.INC'
CLS
PRINT
PRINT "We are in the main Module"
PRINT
Sub1Sub
Sub2Sub
PRINT Sub3Function(Test$)
PRINT Test$
PRINT
PRINT "Press a key to see the Global4$() array passing test"
DO: LOOP WHILE INKEY$ = ""
FOR X% = 1 TO 10
PRINT Sub3Function4$(X%)
NEXT X%
END
'----- End of MAIN.BAS -----
'----- Save as SUB1.BAS -----
DECLARE SUB Sub1Sub ()
' This is SUB1.BAS
' $INCLUDE: 'DECLARE.INC'
' $INCLUDE: 'COMMON.INC'
SUB Sub1Sub
PRINT "Coming to you from SUB1.BAS - SUB Sub1Sub"
PRINT Global1$
PRINT
END SUB
'----- End of SUB1.BAS -----
'----- Save as SUB2.BAS -----
' This is SUB2.BAS
' $INCLUDE: 'DECLARE.INC'
' $INCLUDE: 'COMMON.INC'
Sub2Sub
SUB Sub2Sub
PRINT "Coming to you from SUB2.BAS - SUB Sub2Sub"
PRINT Global2$, Global2%
PRINT
END SUB
'----- End of SUB2.BAS -----
'----- Save as SUB3.BAS -----
' This is SUB3.BAS
' $INCLUDE: 'DECLARE.INC'
' $INCLUDE: 'COMMON.INC'
FUNCTION Sub3Function% (Tmp$)
PRINT "Coming to you from SUB1.BAS - FUNCTION Sub3Functiuon%"
Sub3Function% = Global3%
Tmp$ = Global3$
END FUNCTION
FUNCTION Sub3Function4$ (Tmp%)
Sub3Function4$ = Global4$(Tmp%)
END FUNCTION
'----- End of SUB3.BAS -----
Note: That if you create a new FUNCTION in one of the sub modules
remember to create a declare statement for it and put it in the
DECLARE.INC. Same goes for SUB's, even though QB automatically
adds a DECLARE SUB to your MAIN Module.
Hope it helps you out.
--- Squish v1.01
# Origin: UBU-Midwest - Bensenville IL - 708-766-1089 (8:7401/13)
* Origin: FamilyNet Intl. Echogate [708] 887-7685 (1:115/887)

Books at Amazon:
Back to BASIC: The History, Corruption, and Future of the Language
Hackers: Heroes of the Computer Revolution (including Tiny BASIC)
Go to: The Story of the Math Majors, Bridge Players, Engineers, Chess Wizards, Scientists and Iconoclasts who were the Hero Programmers of the Software Revolution
The Advent of the Algorithm: The Idea that Rules the World
Moths in the Machine: The Power and Perils of Programming
Mastering Visual Basic .NET