Microsoft KB Archive/99457

= FIX: Erase Won't Clear Contents of Huge Fixed Array as Variant =

Article ID: 99457

Article Last Modified on 12/12/2003

-

APPLIES TO


 * Microsoft Visual Basic 2.0 Standard Edition
 * Microsoft Visual Basic 3.0 Professional Edition
 * Microsoft Visual Basic 2.0 Professional Edition
 * Microsoft Visual Basic 3.0 Professional Edition

-



This article was previously published under Q99457



SYMPTOMS
The Erase statement fails to erase huge static arrays of type Variant. This problem occurs with the Variant data type only.

The problem does not occur if the size of the array is less than 64K or if you use a huge dynamic array of type Variant.



CAUSE
This problem occurs with huge static arrays of the variant data type. An array is static when you dimension it with the Static keyword or if you use the DIM keyword to dimension the array in the general-declaration section of a form or module.

The problem occurs because the Erase statement corrupts the array descriptor for a huge static array of variants. However, only the references to the 64K data segments other than the first segment are corrupted. Any elements in the first 64K segment of the array are always erased properly. All elements stored in other segments are not erased.

The Erase statement is only effective the first time you erase the elements of a huge static variant array. Any additional attempt to Erase elements of the array will fail and the elements in the array in data segments other than the first segment will not be erased.



WORKAROUND
To work around the problem, clear each element of the array manually by setting each element to Empty. Replace the &quot;Erase a&quot; statement in step 2 shown below with this code: For i% = 0 to 5000 a(i%) = Empty           '** Empty = 0 Next i%



STATUS
Microsoft has confirmed this to be a bug in Microsoft Visual Basic version 2.0 for Windows. This problem was corrected in Microsoft Visual Basic version 3.0 for Windows.



Steps to Reproduce Problem
 Start Visual Basic, or choose New Project from the File menu (ALT, F, N) if Visual Basic is already running. Form1 is created by default.  Enter the following procedure into the general section of Form1: Sub test

Static a(5000) As Variant 'Huge static variant array

a(1) = 1             '*element 1 is in the first segment a(100) = 2           '*element 100 is in the first segment a(5000) = 3          '*element 5000 is in the second segment

Debug.Print &quot;Before the Erase:&quot; Debug.Print &quot;a(1) = &quot;; a(1) Debug.Print &quot;a(100) = &quot;; a(100) Debug.Print &quot;a(5000) = &quot;; a(5000) Debug.Print &quot;&quot;

Erase a              '*erase the elements

Debug.Print &quot;After the Erase:&quot; Debug.Print &quot;a(1) = &quot;; a(1) Debug.Print &quot;a(100) = &quot;; a(100) Debug.Print &quot;a(5000) = &quot;; a(5000) Debug.Print &quot;&quot;

End Sub   Place the following code in the Form_Click event procedure for Form1: Form_Click Call test End Sub  Press F5 to run the example. Click Form1 to see the following results in the Debug Window:

Before the Erase:

a(1) = 1

a(100) = 2

a(5000) = 3

After the Erase:

a(1) =

a(100) =

a(5000) =

But if you click again, you will see different results:

Before the Erase

a(1) = 1

a(100) = 2

a(5000) = 3

After the Erase

a(1) =

a(100) =

a(5000) = 3



This shows that the elements of the huge static Variant array were not cleared, but the elements of a smaller Variant array were cleared.

Additional query words: buglist2.00 fixlist3.00 1.00

Keywords: kbbug kbfix KB99457

-

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

© Microsoft Corporation. All rights reserved.