
Help! Problem passing string array to sub
I'm using QuickBASIC 4.5 and trying to pass arrays to a subprogram.
It's not working - and is even messing up other variables.
Unlike the examples in the manuals, I'm using a stand-alone subprogram
that I link with the main program (the so-called separate compilation
method).
I tested the subprogram code as a main program by deleting the SUB and
END SUB statements and adding code to get data from the keyboard. It
worked perfectly (but the arrays were then "local," of course). When I
compile the subprogram, I get three "Array not defined" errors, one on
the first occurrence of each of the three arrays.
I get no errors when compiling or linking the main program, but it
doesn't work. I've added code to print the arrays from both the main
and subprogram. The main program loads the arrays correctly but the
data never makes it to the subprogram. Whats more, at least two
variables in the main program are changed by the subprogram call (yet
once defined early in the main program, they're never changed again
and they're not used by the subprogram).
I'm stumped. Does anyone have suggestions for making this work?
Main program:
DECLARE SUB Matrix_Mult ( A$(), B$(), C$() )
DIM A$(500), B$(500), C$(500)
'code to load arrays A$() and B$() from either a file or from
the keyboard
'code to verify arrays A$() and B$() loaded correctly
CALL Matrix_Mult(A$(), B$(), C$())
'code to (again) verify arrays A$() and B$() loaded correctly,
'code to print the product array, C$()
Subprogram:
SUB Matrix_Mult ( A$(), B$(), C$() )
'code to display data in arrays A$() and B$()
'code to do a matrix muliply: A$() * B$() = C$()
END SUB