XL97: Indexes for Methods and Collections are RoundedLast reviewed: March 13, 1998Article ID: Q159874 |
The information in this article applies to:
SYMPTOMSIn Microsoft Excel 97, if you specify a decimal value for the index of a method or collection in a Visual Basic for Applications macro, the index is rounded. This behavior differs from that of earlier versions of Microsoft Excel. In earlier versions, the index is truncated rather than rounded. Because of this difference, if your macro relies on Microsoft Excel to convert decimal values for the indexes of methods or collections, your macro may provide different results in different versions of Microsoft Excel.
CAUSEMicrosoft Excel 97 utilizes stricter typing for arguments of collections and methods. If an argument is typed as an integer, decimal values that are passed to that argument are automatically rounded.
RESOLUTIONThe example below demonstrates a situation where you receive conflicting results between versions of Microsoft Excel.
MsgBox Sheets(1.6).NameIn Microsoft Excel 97, 1.6 is rounded to 2 and this line of code will reference the second Sheet in the Sheets collection. In Microsoft Excel versions 5.0 and 7.0, the number 1.6 is truncated to 1 and this line of code references the first Sheet in the Sheets collection. You should not rely on Microsoft Excel to automatically convert your decimal values for indexes. If you require that the index be truncated in all versions of Microsoft Excel, use the INT function:
MsgBox Sheets(INT(1.6)).NameIf you require that the index be rounded in all versions of Microsoft Excel, use the CInt function:
MsgBox Sheets(CInt(1.6)).Name STATUSThis is by design in Microsoft Excel 97.
|
Additional query words: XL97 8.00 fraction integer convert conversion
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |