FIX: GPF When Erase User-Defined Array of Variable Strings

Last reviewed: October 30, 1997
Article ID: Q95525
2.00 WINDOWS kbprg kbbuglist

The information in this article applies to:

- Microsoft Visual Basic programming system for Windows, version 2.0

SYMPTOMS

If you try to erase an user-defined type array of a variable-length strings, you may encounter a general protection (GP) fault or unrecoverable application error (UAE).

WORKAROUND

This problem doesn't occur if you use an array of fixed-length strings or an array of type Variant in place of the array of variable-length strings. Therefore, you can work around the problem by using an array such as the following with a user-defined type and fixed-length strings.

   Type mytype
      mystrings(1) As String * 10   'array of fixed length string
   End Type

   Global test As mytype

You can also work around the problem by using an array of variants instead of an array of strings, as this example shows:

   Type mytype
      mystrings(1) As Variant      'array of variant type
   End Type

   Global test As mytype

A third alternative is to erase the elements in the variable-length string array manually instead of using the Erase statement, as follows:

   Form_Click()
   For i% = 0 to UBound(test.mystrings)
      test.mystrings(i%) = ""
   Next i%
   End Sub

STATUS

Microsoft has confirmed this to be a problem 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. Run Visual Basic, or if Visual Basic is already running choose New Project from the File menu (ALT, F, N). Form1 is created by default.

  2. From the File menu, choose New Module (ALT, F, M). Module1 will be created.

  3. Add the following code to the general declarations section of Module1:

          Type mytype
    
             mystrings(1) As String
          End Type
    
          Global test As mytype
    
    

  4. Next add the following code to the Form_Click event procedure of Form1:

          Form_Click()
    
             Erase test.mystrings(1)
          End Sub
    
    

  5. Press the F5 key and click Form1.

At this point, you will encounter a GP fault or UAE.


Additional reference words: buglist2.00 fixlist3.00 2.00 3.00
KBCategory: kbprg kbbuglist
KBSubcategory: PrgOptTips
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.