This article was previously published under Q31557
This article has been archived. It is offered "as is" and will no longer be updated.
An array of fixed-length strings cannot be passed directly as aparameter to a SUBprogram or FUNCTION procedure (that is, the phraseAS STRING*n cannot be used in DECLARE, SUB, or FUNCTION statements).
The following are three alternatives for passing an array offixed-length strings to a procedure:
Pass the array of fixed-length strings through COMMON SHARED. (Please see Example 1 below.)
Convert the array of fixed-length strings to an array of user-defined type and pass the array AS that type. (Please see Example 2 below or the TORUS.BAS sample program provided on the release disk.)
Convert the array of fixed-length strings to an array of user-defined type and pass that array through COMMON SHARED. (Please see Example 3 below.)
This information applies to QuickBasic Versions 4.00, 4.00b and 4.50,to Microsoft Basic Compiler Versions 6.00 and 6.00b for MS-DOS andOS/2, and to Microsoft Basic Professional Development System (PDS)Versions 7.00 and 7.10 for MS-DOS and MS OS/2.
Note that when you pass a simple fixed-length string variable to aprocedure, it is always converted to a variable-length string. Thus,the variable-length STRING type is allowed in DECLARE, SUB, andFUNCTION statements, but the fixed-length STRING*n type is not.
The following is an example (Example 1) of how to pass an array offixed-length strings through COMMON SHARED:
DECLARE SUB TEST() DIM X(1 TO 30) AS STRING*22 COMMON SHARED X() AS STRING*22 X(5)="THIS IS A TEST" CALL TEST END SUB TEST STATIC PRINT X(5) END SUB
The following is an example (Example 2) of how to pass an array ofuser-defined type as a parameter to a procedure:
DECLARE SUB sub1 (t() AS ANY) TYPE mytype y AS STRING * 10 END TYPE DIM t(10) AS mytype CALL sub1(t()) PRINT t(1).y END SUB sub1 (t() AS mytype) t(1).y = "test" END SUB
The following is an example of how to pass an array of user-definedtype through COMMON SHARED:
TYPE mytype FIRST AS STRING*25 END TYPE DIM AR(9) AS mytype COMMON SHARED AR() AS mytype, TEMP AS INTEGER AR(5).FIRST="This is fifth element" TEMP=99 CALL TEST END SUB TEST STATIC PRINT AR(5).FIRST PRINT TEMP END SUB
Microsoft QuickBasic 4.0, Microsoft QuickBASIC 4.0b, Microsoft QuickBasic 4.5 for MS-DOS, Microsoft BASIC Compiler 6.0, Microsoft BASIC Compiler 6.0b, Microsoft BASIC Professional Development System 7.0, Microsoft BASIC Professional Development System 7.1