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

Last reviewed: October 30, 1997
Article ID: Q99457
2.00 3.00 WINDOWS kbenv kbbuglist

The information in this article applies to:

- Standard and Professional Editions of Microsoft Visual Basic programming

  system for Windows, versions 2.0 and 3.0

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 "Erase a" 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.

MORE INFORMATION

Steps to Reproduce Problem

  1. 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.

  2. 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 "Before the Erase:"
         Debug.Print "a(1) = "; a(1)
         Debug.Print "a(100) = "; a(100)
         Debug.Print "a(5000) = "; a(5000)
         Debug.Print ""
    
         Erase a               '*erase the elements
    
         Debug.Print "After the Erase:"
         Debug.Print "a(1) = "; a(1)
         Debug.Print "a(100) = "; a(100)
         Debug.Print "a(5000) = "; a(5000)
         Debug.Print ""
    
       End Sub
    
    

  3. Place the following code in the Form_Click event procedure for Form1:

    Form_Click ()

          Call test
    
       End Sub
    
    

  4. 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 reference words: buglist2.00 fixlist3.00 1.00
KBCategory: kbenv kbbuglist
KBSubcategory: EnvtRun
Solution Type : kbfix


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: October 30, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.