Thursday, July 19, 2018

#1 2011-02-25 04:19:57 am

zboy02043
Member
Registered: 2010-05-02
Posts: 5

having a slight problem

ok so i'm not sure if this is the right place for this but here goes..

so in my script i have two lists, one of numbers (ie. {"1", "2", "3", "4", "5"})

and one of signs (ie. {"+", "-", "*", "/"})

my ultimate goal is that i can do something with these to DO MATH big_smile

i want for the equation 1+2-3*4/5 to be solved with my script but i can't figure out how to change the signs from text items to the actual operators. is there any way to do this or am i outa luck?

Offline

 

#2 2011-02-25 05:04:11 am

DJ Bazzie Wazzie
Member
From:: the Netherlands
Registered: 2004-10-20
Posts: 2777
Website

Re: having a slight problem

What you're looking for is called an eval. Most interpreter languages have an eval but you have to be aware of the danger of using them. The eval command of applescript is run script.

Applescript:

run script "1 + 1" --result: 2 of class integer

What this does is interpreting the string as code and compile/execute it. When a string from a user input (from dialogs, input fields etc) is used inside an eval you have a security issue because users are able to run own code through injection.

Offline

 

#3 2011-02-25 04:08:46 pm

zboy02043
Member
Registered: 2010-05-02
Posts: 5

Re: having a slight problem

ok thank you, but what would i actually put in the code to make this work for my situation?

edit:

i've tried code like
(the list of numbers is numberlist and the list of signs is signlist)

run script item 1 of numberlist item 1 of signlist item 2 of numberlist

this gives the error: Expected end of line, etc. but found class name.

so i tried just with the signlist

run script item 1 of signlist

which gave me the error: Scripting component error.

so i'm kinda lost D:

Last edited by zboy02043 (2011-02-25 04:19:29 pm)

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)