Evaluate a formula given as string

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Reshmi Jacob
    New Member
    • Sep 2006
    • 50

    Evaluate a formula given as string

    Hello.....


    In my program I have 3 variables, say

    a = 10
    b = 20
    c = 30

    I have a variable as string
    vformula = "a + b + c"

    I have to evaluate the formula and get the result as 60
    ie ; myanswer = SOMEFUNCTION(vf ormula).

    I tried using Scriptcontrol.E VAL function. But I can use only " 10 + 20 + 30".
    Also, when I browse thru net I found something lilke CInt(a) + CInt(b) + CInt(c). This is also not applicable since I wont be knowing the formula & variables in advance.

    Pls Help, thanks in advance....

    Regards
    Reshmi
  • Killer42
    Recognized Expert Expert
    • Oct 2006
    • 8429

    #2
    I suggest you try the search box, up top. This question has come up before. The answer, as I recall, involved the use of the MS Scripting Runtime.

    Comment

    • Reshmi Jacob
      New Member
      • Sep 2006
      • 50

      #3
      Hello

      Thanks for the reply.

      I have tried Script Control, but using this I can evaluate only " 10 + 20 + 30" not "a + b + c".

      Regards
      Reshmi

      Originally posted by Killer42
      I suggest you try the search box, up top. This question has come up before. The answer, as I recall, involved the use of the MS Scripting Runtime.

      Comment

      • Killer42
        Recognized Expert Expert
        • Oct 2006
        • 8429

        #4
        Originally posted by Reshmi Jacob
        I have tried Script Control, but using this I can evaluate only " 10 + 20 + 30" not "a + b + c".
        Hm... not sure how you'd go about this.

        At the simplest level, of course, if you know the variable names that can be used, you could do a substitution in the string before submitting it for processing. In other words, replace a with the value of a, b with the value of b, and so on.

        Comment

        Working...