# From string to expression

## Recommended Posts

I am working with a script that will draw parametric equations. However, i have a bit of a problem with it.

I ask the user for an equation, lets say for X. An example would be sin(\$T) where \$T is time.

I managed to have it evaluate T and i get the string "sin(0)" by using:

\$mX = StringReplace(\$xEq,"\$T",\$T)

(by the way \$mX is where the mouses X coordinate is, and \$xEq is the string equation)

so now i have "sin(0)" how do i get that to evaluate? ive tried stuff like:

\$mX = Number(\$mX) but that seems to be only for direct numbers, like "4.62".... Any help? I need it to evaluate any string like:

"(Sin(1.4) * Cos(1.4)) * 100 + 500"

Any ideas? Thanks!

##### Share on other sites

I am working with a script that will draw parametric equations. However, i have a bit of a problem with it.

I ask the user for an equation, lets say for X. An example would be sin(\$T) where \$T is time.

I managed to have it evaluate T and i get the string "sin(0)" by using:

\$mX = StringReplace(\$xEq,"\$T",\$T)

(by the way \$mX is where the mouses X coordinate is, and \$xEq is the string equation)

so now i have "sin(0)" how do i get that to evaluate? ive tried stuff like:

\$mX = Number(\$mX) but that seems to be only for direct numbers, like "4.62".... Any help? I need it to evaluate any string like:

"(Sin(1.4) * Cos(1.4)) * 100 + 500"

Any ideas? Thanks!

I believe you require the Execute() command.

Here is another similar example to the help file example.

```;
\$iVar = 30                                     ; Degrees
\$sEq = "Sin(\$iVar*4*atan(1)/180) * 100 "     ; 4*atan(1) = pi
MsgBox(0, "Answer", Execute(\$sEq))             ; sin(30deg)*100 = 50
;```

##### Share on other sites

I believe you re correct. I don't even need to replace from the looks of it, thanks!!!

## Create an account

Register a new account