Help! Problem passing string array to sub 
Author Message
 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



Sat, 22 Aug 1998 03:00:00 GMT  
 Help! Problem passing string array to sub

Quote:

>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

Good morning, Bill

I think I understand what you're doing correctly. You're compiling
your main program as one module, and then you're compiling your
subprogram as another module, and linking them at the final compile.
I hope that is correct.

I think what you need is a COMMON statement at the top of each module.

COMMON A$(), B$(), C$().

However, depending on the length of the subroutine, I don't see why
you don't put it in the main module. I just ran the outline code above
through VBDOS, and didn't get any errors at all. So, instead of
compiling two modules and linking them, why not just one module?

Hope this helps. God Bless.

Norm Jacobson, The Salvation Army
Mail: 1708 18th St., #3, Lubbock, TX 79401-4838



Mon, 24 Aug 1998 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Passing as string variable from sub to sub

2. Problem in passing datarow array from one sub to other

3. Help! Passing option arrays to sub

4. Help how to pass control arrays to sub ??

5. Help passing array to bas module sub

6. Problem passing arrays of strings to C DLL

7. help with pass string array to C DLL procedure

8. pass an array as function/sub argument

9. Question on passing array parameters to VB.NET Sub/Function

10. Passing Arrays from Sub to Program

11. Passing Property Arrays to Sub Routines

12. vb5 Passing an array of type MENU to a Sub

 

 
Powered by phpBB® Forum Software