"Duplicate Definition," CHAIN, Dynamic Array in COMMON (82912)



The information in this article applies to:

  • Microsoft QuickBASIC Compiler for the Apple Macintosh 1.0
  • Microsoft QuickBASIC Compiler for the Apple Macintosh 1.0a
  • Microsoft QuickBASIC Compiler for the Apple Macintosh 1.0b

This article was previously published under Q82912

SUMMARY

CHAINing with a dynamic array in a COMMON statement will give a "Duplicate Definition" (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 "Make All Arrays Static" 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 "Program2 apl"
   END
				

Program2

 
  COMMON array1(1), flag
   flag = 100
   array1(1)=array1(1)+1
   PRINT array1(1)
   CHAIN "Program1 apl"
   END
				

Modification Type:MajorLast Reviewed:10/20/2003
Keywords:KB82912