#1
  1. Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2003
    Posts
    3
    Rep Power
    0

    Storing & Using Operators


    Hi

    I have a situation where I need to store an operator (i.e. * or /)

    I then want to retrieve this operator and use it in a calculation.

    e.g.


    Store * in a database


    Retrieve the * from database
    Assign * to a variable

    Dim strVariable

    strVariable = *

    intResult = 1 strVariable 2 'Result being 2

    Can anyone help please
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2001
    Location
    Dublin
    Posts
    413
    Rep Power
    14
    if you're just performing a one operator binary operation as in your example then just use
    Code:
    Public Function Calculate(ByVal operand1 As Double, ByVal operation As String, ByVal operand2 As Double
    Dim retVal as Double
      Select Case operation
        Case "*": Let retVal = operand1 * operand2
        Case "/": Let retVal = operand1 / operand2
        Case Else:Call Err.Raise("todo")
      End Select: Let Calculate=retVal
    If you need to parse a more complicated expression then you'll need to use a binary tree / series of recursive functions, I think

IMN logo majestic logo threadwatch logo seochat tools logo