Microsoft KB Archive/82912

= &quot;Duplicate Definition,&quot; CHAIN, Dynamic Array in COMMON =

Article ID: 82912

Article Last Modified on 10/20/2003

-

APPLIES TO


 * Microsoft QuickBasic Compiler for Macintosh 1.0
 * Microsoft QuickBasic Compiler for Macintosh 1.0
 * Microsoft QuickBasic Compiler for Macintosh 1.0

-



This article was previously published under Q82912



SUMMARY
CHAINing with a dynamic array in a COMMON statement will give a &quot;Duplicate Definition&quot; (run-time error 10) at run time if the CHAINed program attempts to dimension the array again without first erasing the array.

Dynamic arrays are dimensioned at run time, while static arrays are dimensioned at compile time. A dynamic array needs to be dimensioned only once in the executable code; it must be erased before executing another DIM statement for that array.

The compiler in QuickBasic allows you to make some arrays static (with DIM STATIC) and some arrays dynamic in a program. You can also choose the &quot;Make All Arrays Static&quot; option from the Options item in the Run menu.

Arrays are always dynamic in the interpreter in QuickBasic. The interpreter does not support static arrays. Dynamic arrays cannot be redimensioned unless you first perform an ERASE. The ERASE statement removes a dynamic array from memory.

This information applies to Microsoft QuickBasic versions 1.0, 1.0a, and 1.0b for Apple Macintosh.



MORE INFORMATION
In a CHAIN operation, a dynamic array is passed in the COMMON statement, but needs only to be dimensioned in the CHAINing program. If the CHAINed program CHAINs back to the CHAINing program, the CHAINing program must incorporate logic so the DIM statement is not executed a second time.

You can do this by passing a flag variable between programs in a COMMON statement. This flag variable is used in an IF statement to execute the DIM statement only once. This technique works with any Microsoft Basic interpreter or compiler that supports dynamic arrays.

The following is an example of how to CHAIN between programs that pass a dynamic array in a COMMON statement:

Program1
COMMON array1(1), flag IF flag <> 100 DIM array1(20) END IF  array1(1) = 0 IF array1(1) > 5 THEN STOP CHAIN &quot;Program2 apl&quot; END

Program2
COMMON array1(1), flag flag = 100 array1(1)=array1(1)+1 PRINT array1(1) CHAIN &quot;Program1 apl&quot; END

Additional query words: MQuickB 1.00 1.00a 1.00b

Keywords: KB82912

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.