'===========================================================================
' Subject: SHARE DATA BETWEEN SUBS            Date: 10-23-97 (00:12)       
'  Author: Robert Fortune                     Code: Text                   
'  Origin: FidoNet QUIK_BAS Echo            Packet: FAQS.ABC
'===========================================================================
'>I've been studying QBasic for a while [...]
'>Anyhoo, I can't figure out how to transfer data between subs.
'>explain this.

   If you mean you want to share data *between* SUBs you can make the
   variables that you want all of your SUBs (and\or FUNCTIONs) to share
   global by using DIM SHARED in your main module. As in:

   DIM SHARED MyVariable%, Total&, FullName$

   You would put that DIM SHARED statement in your program's main module
   (not in a SUB or FUNCTION). Doing that means that any SUB (or FUNCTION)
   in your program can share those variables with your main module.

      If you only want a single SUB to share specific variables with the
   main module you can use:

   DECLARE SUB Hello()
   Text$ = "Hello"
   Hello           ' Call the Hello SUB
   END             ' End of main program

   SUB Hello       ' The Hello SUB
    SHARED Text$   ' Text$ from your main module is shared with this sub
    PRINT Text$
   END SUB

     Or you can pass the variable when you call the SUB as in:

   DECLARE SUB AMessage(Text$)
   Text$ = "A fair disposition is essential to a successful life."
   CALL AMessage(Text$)  ' pass the variable to the SUB AMessage
   END      ' End of main program

   SUB AMessage(Text$)
      PRINT AMessage$
   END SUB

   Here's some code that uses each of the 3 methods I described above.

' ------------- CUT HERE ----------------- CUT HERE ----------------------
REM SHRDATA.BAS
REM Different ways that you can share data with your SUBs and\or FUNCTIONs
REM 10/23/1997
DEFINT A-Z        ' All untyped variables default to type integer
DECLARE SUB Hello ()
DECLARE SUB WhatUp ()
DECLARE SUB Goodbye (Bye$)

' 1) Share the string variable Text$ with all SUBs (and\or FUNCTIONs)

DIM SHARED Text$  ' string variable Text$ is shared with all SUBs\FUNCTIONs
CLS
PRINT

Text$ = "Hello World!"
Hello             ' call the Hello SUB


' 2) Share the string variable Message$ with just the Whatup SUB

Message$ = "What's up with that?"
WhatUp            ' see the WhatUp SUB where Message$ is declared SHARED


' 3) Share the string variable Bye$ by passing it when the SUB is called

Bye$ = "Goodbye world!"
Goodbye (Bye$)    ' Bye$ is passed to be shared with the Goodbye SUB
PRINT
PRINT "Thethethe... that's all folks! <g>"
END

SUB Goodbye (Bye$)
 PRINT Bye$
END SUB

DEFINT A-Z
SUB Hello
 PRINT Text$
END SUB

DEFINT A-Z
SUB WhatUp
 SHARED Message$  ' Share Message$ (from main module) with this SUB
 PRINT Message$
END SUB
' ------------- CUT HERE ----------------- CUT HERE ----------------------

 Hope that helps. Good luck!
