• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Solving equations (was Re: Unquoting a string)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Solving equations (was Re: Unquoting a string)


  • Subject: Solving equations (was Re: Unquoting a string)
  • From: JollyRoger <email@hidden>
  • Date: Mon, 15 Jul 2002 08:33:19 -0500

What you are trying to do is actually very easy.

You don't need to remove quotes. All you need to do is make the string a
script by appending something like "set x to " to the equation, and then
telling AppleScript to run the string as if it were a script.

Example:

-- begin script
-- ask user for an equation
display dialog "Please type an equation here:" default answer "Type Here..."

-- get the equation text
set equation to (text returned of the result)

-- run the equation text as a script, putting the result in answer
set the answer to run script equation

-- display the result
display dialog "the result is: " & answer buttons "Cool!" default button 1
-- end script

...or:

-- begin script
-- ask user for an equation
display dialog "Please type an equation here:" default answer "Type Here..."

-- one-liner
display dialog "the result is: " & (run script (text returned of the
result)) buttons "Cool!" default button 1
-- end script

HTH

JR

On 7/14/2002 6:32 PM, "Robert Stretch" <email@hidden> wrote:

> Hi there,
>
> If I have the small scripts:
>
> 2 * 2 OR 2 + 2 etc...
>
> The only way for AppleScript not to recognize them as a string of text
> is for me not to have them in quotes (" "). So what happens when I have
> a dynamic string of text which needs to be equated? For example if i
> display a dialog with a text field like so:
>
> set theEquation to display dialog "Please type an equation here:"
> default answer "Type Here..."
>
> Then the result is a QUOTED equation. So my question is, after all
> that, how do I make it so that AppleScript recognizes the equation for
> what it is supposed to be, an unquoted equation, and calculate it?
>
> Best Wishes
> Robert Stretch
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.

  • Follow-Ups:
    • Re: Solving equations (was Re: Unquoting a string)
      • From: Stephen Swift <email@hidden>
    • Re: Solving equations (was Re: Unquoting a string)
      • From: Emmanuel <email@hidden>
References: 
 >Unquoting a string (From: Robert Stretch <email@hidden>)

  • Prev by Date: Re: has's list wrappers [Re: Passing *possible* variables to a
  • Next by Date: Re: Moving Icons Was: Writing to a file
  • Previous by thread: Re: Unquoting a string
  • Next by thread: Re: Solving equations (was Re: Unquoting a string)
  • Index(es):
    • Date
    • Thread