Eval with a variableMenu

Applies to:Fast Math Parser
Evaluating an expression with variables
What if you want to evaluate an expression with a variable in it? First define the variable with DefineVariable, then you can later use it in your expression: #c uc.DefineVariable("x = 123") Answer = uc.Eval("5+x*10") #c What if we wanted to set the variable value later, instead of hardcoding an initial value? Once a variable is defined, we don't want to call DefineVariable again each time we want to set or change the variable value. Instead we'll use SetVariableValue (we'll learn more about it later) like this: #c Variable.SetVariableValue(123) Answer = uc.Eval("5+x*10") #c Note: In C++ replace Dim with ``auto``, and C# with ``var`` You can have as many variables as you like. And you can name them what you want. #c Dim Length = uc.DefineVariable("Length") Dim Width = uc.DefineVariable("Width") Length.SetVariableValue(10) Width.SetVariableValue(20) Answer = uc.Eval("Length * Width") #c
Prev | Next