Option Base with User-Defined Type Incorrect in Help Topic (135879)
The information in this article applies to:
- Microsoft Excel for Windows 95 7.0a
- Microsoft Excel for Windows 5.0c
- Microsoft Excel for the Macintosh 5.0a
This article was previously published under Q135879 SYMPTOMS
In the versions of Microsoft Excel listed above, the Help topic for the
Visual Basic Option Base statement contains the following information:
The Option Base statement has no effect on arrays within user-defined
types for which the lower bound is always 0.
This information is not entirely correct.
CAUSE
This statement is not true for an array within your user-defined type. For
example, when you run the following code, the value 1 is returned, instead
of the expected value 0 for the lower bound of the array within the user-
defined type Mytype:
Option Base 1
Type Mytype
Machine(2) As String
End Type
Sub Test_Mytype()
Dim Test As Mytype
MsgBox LBound(Test.Machine)
End Sub
WORKAROUNDMicrosoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements.
If you want the lower bound for an array within your user-defined type to
be zero, you can use any of the following methods.
Method 1
Use the "To" clause to explicitly define the upper and lower bounds of your
array. This method overrides any Option Base settings in your module. The
following is an example of using this method:
Type Mytype
Machine(0 To 2) As String
End Type
Method 2
Use the Option Base statement with the value 0 by adding the following
statement at the beginning of your module:
Option Base 0
Method 3
Do not use the Option Base statement at all; the default base is 0.
STATUS
Microsoft has confirmed this to be a problem in the Microsoft products
listed at the beginning of this article. This problem was corrected in
Microsoft Excel 97 for Windows and Microsoft Excel 98 Macintosh Edition.
REFERENCES
For more information about the "Option Base Statement," choose the Search
button in the Visual Basic Reference (version 5.0) and type:
Modification Type: | Minor | Last Reviewed: | 10/11/2006 |
---|
Keywords: | kbbug kbcode kbfix kbProgramming KB135879 |
---|
|