Jump to content

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!

Link to comment
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
;
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...