WordBasic Error with Array Dimensioned for 0 (Zero) Elements

ID: Q105549

The information in this article applies to:

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

Last Reviewed: July 30, 1997