Class: ExpressionEvaluator in Category General VBA/VB6 : String Handling from Total Visual SourceBook

Class to implement expression evaluation in VBA and VB6.

Expression evaluation is a common need in many programs, especially if you deal with numbers and operators.

Procedure Name Type Description
(Declarations) Declarations Declarations and private variables for the CExpressionEvaluator class.
Expression Property Get the expression to evaluate.
Postfix Property Get the postfix representation of the expression string.
Class_Initialize Initialize Set initial values to defaults which may be overridden with property settings.
Evaluate Method Evaluates the expression. For simplicity the postfix representation of the expression is evaluated.
CharType Private Determine the type of the current character.
ConvertToPostfix Private Converts the expression to postfix and stores the result in m_strPostfix.
GetNextToken Private Get the next token in the string identified by the text property.
HandleSeparator Private Handles a separator character.
HandleToken Private Handles a token character.
HandleWhiteSpace Private Handles a whitespace character.
ParseExpression Private Parses an expression.
ParseFactor Private Parses a factor.
ParseTerm Private Parse a term. A term is something like 2+7, or 1 + sin(1), while a token is the smallest meaningful piece of data, such as 2 or sin.
PopResult Private Pops an item off the stack.
PushResult Private Pushes an item onto the stack.
SetTokenString Private Set the string used by the tokenizer.
' Example of CExpressionEvaluator
' To try this example, do the following:
' 1. Add a command button named 'cmdTest'
' 2. Paste all the code from this example to the new form's module.
' 3. Run the form

Private mExpressionEvaluator As CExpressionEvaluator

Private Sub cmdTest_Click()
  Dim dblResult As Double
  Set mExpressionEvaluator = New CExpressionEvaluator

  With mExpressionEvaluator
    .Expression = "5 * 10 / (12.5 * 2)"
    dblResult = .Evaluate
    Debug.Print "5 * 10 / (12.5 * 2) = " & dblResult
  End With

End Sub

Total Visual SourceBook The source code in Total Visual Sourcebook includes modules and classes for Microsoft Access, Visual Basic 6 (VB6), and Visual Basic for Applications (VBA) developers. Easily add this professionally written, tested, and documented royalty-free code into your applications to simplify your application development efforts.

Total Visual SourceBook is written for the needs of a developer using a source code library covering the many challenges you face. Countless developers over the years have told us they learned some or much of their development skills and tricks from our code. You can too!

Additional Resources

Total Visual SourceBook CD and Printed Manual

Microsoft Access/ Office 2016, 2013, 2010, and 2007 Version
is Shipping!

New features in Total Visual SourceBook for Access, Office and VB6

Supports Access/Office 2016, 2013, 2010 and 2007, and Visual Basic 6.0!

View all FMS products for Microsoft Access All Our Microsoft Access Products


Reader Choice Award for MS Access Source Code Library
Reader Choice

"The code is exactly how I would like to write code and the algorithms used are very efficient and well-documented."

Van T. Dinh, Microsoft MVP

SourceBook Info

Additional Info




Free Product Catalog from FMS