BBS: Inland Empire Archive
Date: 04-03-92 (23:35) Number: 106
From: STEVE HALKO Refer#: NONE
To: ZACK JONES Recvd: NO
Subj: Help with subs Conf: (2) Quik_Bas
ZJ>'with the program. If I'm wrong, please point it out. I'm trying to
ZJ>'pass the value of Source$ from the SUB back to the main program.
ZJ>'Everytime I run this the print Source$ prints nothing.
ZJ>DECLARE SUB GetFile (Source$)
ZJ>COMMON SHARED Source$
ZJ>Source$ = RTRIM$(LTRIM$(COMMAND$))
ZJ>IF Source$ = "" THEN
ZJ> GetFile (Source$)
ZJ>SUB GetFile (Source$)
ZJ>DO WHILE Source$ = ""
ZJ>LOCATE 5, 2: PRINT "Name of file to get?"
ZJ>LOCATE 5, 23: PRINT " "
ZJ>LOCATE 5, 23: INPUT "", Source$
ZJ>LOCATE 6, 23: PRINT Source$
First of all, if you're going to pass Source$ as a parameter, you
don't need to make it SHARED unless there are other SUBs which also
need it. And if you're going to make it SHARED, then you don't need
to pass it as a parameter. It won't do any harm either way, though.
Also, if you want to make it shared, you only need COMMON SHARED to
share it with other modules. If you only have one module like you
posted here, just use DIM SHARED Source$.
Anyway, the problem is in the way you're calling GetFile.
GetFile (Source$) means that you're passing Source$ by value. That
means that your SUB gets a copy of the variable Source$. So GetFile
can use it, but it can't change the original Source$ from your main
code. You need to pass it by reference like this:
CALL GetFile (Source$)
GetFile Source$ <-------- without parentheses
To pass a parameter by value - CALL MySub ((Parameter))
To pass a parameter by refernce - CALL MySub (Parameter)
* SLMR 2.1a * DMD $ W( .
--- DB B1063/002487
* Origin: Gulf Coast BBS -QuickSHARE #2- (904)563-2547 HST/V.32bis (1:365/12)