BUG: Compiled Static Array in SUB, Err 10 Duplicate Definition (77736)






This article was previously published under Q77736

SYMPTOMS

A compiled program using static arrays implicitly declared in a static SUB will incorrectly give a run-time error 10, "Duplicate Definition," on the second call to that SUB.

Microsoft has confirmed this to be a bug with the compiler in Microsoft QuickBasic version 1.0b for the Macintosh . Microsoft is researching this problem and will post new information here as it becomes available.

This problem does not occur in programs interpreted in QuickBasic 1.0b.

MORE INFORMATION

The error 10 ("Duplicate Definition") shows that on the second call to the subprogram, the compiled code mistakenly thinks the array element is being redefined as a different type.

The following steps demonstrate this problem in compiled programs:

  1. Type the following code in QuickBasic for Macintosh:
    Call MySub              'First call to SUB.
    Call MySub              'Second call will cause error.
    
    Sub MySub Static        'This Sub Initializes contents of an array.
       For i = 0 to 9
            MyArray(i) = i
       Next i
    End Sub
    						
  2. From the Run menu, select "Options..." and then make sure the "Make All Arrays Static" box is checked.
  3. Compile the program, and run the resulting compiled program.
Here is how you would need to change the above code to have it work properly:
Dim MyArray (10)                'Dimension the array at the module level.
Call MySub
Call MySub

Sub MySub Static
   Shared MyArray()     'Declare the array shared so it uses the same
   For i = 0 to 9               'array that was DIM'ed at the module level
        MyArray(i) = i
   Next i
End Sub
				

Modification Type: Minor Last Reviewed: 1/8/2003
Keywords: kbbug KB77736