WordBasic Error with Array Dimensioned for 0 (Zero) Elements

Last reviewed: July 30, 1997
Article ID: Q105549
The information in this article applies to:
  • Microsoft Word for Windows, versions 6.0, 6.0a, 6.0c
  • Microsoft Word for Windows 95, version 7.0

SYMPTOMS

If you dimension an array with no elements using a statement such as Dim Array$(-1), a WordBasic error occurs when you run the macro. This problem did not occur in Word version 2.x for Windows.

As a result, if your macro dimensions an array based on a count, the macro fails if the count is 0 (zero). For example, the following macro will fail if the last FileFind statement finds no matches:

   Dim Array$(CountFoundFiles() - 1)

This also means you cannot display an empty list box in a dialog box; it must always contain one empty element.

STATUS

We are researching this problem and will post new information here in the Microsoft Knowledge Base as it becomes available.

WORKAROUND

You must rewrite your macro so it contains no arrays with 0 elements. For example, use the following statement to dimension an array that contains an extra element:

   (Dim a$(countfoundfiles()))

When you write a new macro, check to be sure your array will not contain 0 elements.

MORE INFORMATION

An array in WordBasic has as many elements as its last index plus 1, which means that an array dimmed as 0 actually has one element. Therefore, Dim Array$(-1) dimensions an array with no elements.

Kbcategory: kbusage kbmacro KBSubcategory:


Additional query words: 6.0 winword word6 6.0a 6.0c 7.0 word95
word7
Version : 6.0 6.0a 6.0c 7.0
Platform : WINDOWS


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: July 30, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.