The information in this article applies to:
SUMMARYThere is no built-in function to return the number of dimensions in an array variable in Microsoft Visual Basic for Applications. The easiest way to do this is by looping through the dimensions and using an error handler to return the number of dimensions. MORE INFORMATIONMicrosoft provides programming examples for illustration only, without warranty either expressed or implied, including, but not limited to, the implied warranties of merchantability and/or fitness for a particular purpose. This article assumes that you are familiar with the programming language being demonstrated and the tools used to create and debug procedures. Microsoft support professionals 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 needs. If you have limited programming experience, you may want to contact the Microsoft fee-based consulting line at (800) 936-5200. For more information about the support options available from Microsoft, please see the following page on the World Wide Web: http://www.microsoft.com/support/supportnet/overview/overview.aspThe easiest way to determine the number of dimensions in a Visual Basic for Applications array variable is to get the routine to attempt a task with each dimension. When it attempts to do the task to a nonexistent dimension, an error will be returned. An error handler can be used to return the dimension in which the task was last successful. One way to test a dimension is by using the LBound function. The LBound function takes two arguments, the array variable and the specific dimension, and returns the lower bounds of that dimension. Using this function on a nonexistent dimension returns an error. Coupled with an error handler, this can be used to determine the number of dimensions. Sample Visual Basic ProcedureThis routine tests the array named Xarray by testing the LBound of each dimension. Using a For...Next loop, the routine cycles through the number of possible array dimensions, up to 60000, until an error is generated. Then the error handler takes the counter step that the loop failed on, subtracts one (because the previous one was the last one without an error), and displays the result in a message box.
REFERENCESFor additional information about getting help with Visual Basic for Applications, please see the following article in the Microsoft Knowledge Base: Q163435 VBA: Programming Resources for Visual Basic for Applications Additional query words: 5.00a 5.00c 8.00 XL97 XL98 XL7 XL5 statistical error
Keywords : kbprg kbdta kbdtacode PgmHowto KbVBA |
Last Reviewed: November 9, 1999 © 2000 Microsoft Corporation. All rights reserved. Terms of Use. |