HOWTO: Evaluate Numeric Expressions Stored as a StringLast reviewed: September 30, 1997Article ID: Q159974 |
The information in this article applies to:
SUMMARYGiven a string expression, the Val function returns the number contained in that string. However, if it encounters a character that is not a number or part of a number, it ignores the rest of the string. For example, Val("2") returns the number 2, but Val("2+2") also returns the number 2, and Val("(2+2)") returns the number 0. This article describes how to obtain the actual value of a numeric expression that is stored as a String by using the existing features in the Excel Object Model.
MORE INFORMATIONIn some instances, you might want to allow users to type in their own numeric expression in a TextBox and then evaluate it. In other cases, it might be necessary to read an ASCII file that contains a series of numeric expressions and then produce another ASCII file containing the results of those expressions. If this is the only purpose of your Visual Basic application, it is probably best, for speed and efficiency, to write a parser. However, for a simple and quick solution, you can use OLE Automation and the Excel Object Library to accomplish these tasks.
Step-by-Step Example
Keywords : VB4ALL VB4WIN vbwin GnrlVb kbprg Technology : kbole kbvba Version : WINDOWS:4.0 Platform : NT WINDOWS Issue type : kbhowto |
================================================================================
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |