Re: run script
Re: run script
- Subject: Re: run script
- From: has <email@hidden>
- Date: Thu, 25 Oct 2001 14:18:40 +0100
Nicolas Descombes wrote:
>
Hello,
>
>
I'm french and I'm sorry for my english.
Way better than my French.:)
>
I would want, with a dialog box, enter a formula with one or more variables.
>
I tried with this script but AppleScript wants that I define the variable
[snip]
>
How can I do to define the variable and obtain a result for my formula
The following script allows you to type in one or more lines of script by
using semi-colons to indicate returns (since you can't use returns in the
dialog), eg:
set x to 5; set y to 3; x div y
--> 1
If you need to use semi-colons normally then change this character to
something else.
I've also included some basic error trapping.
======================================================================
property yourDelim : ";" --character used to break statements
try
set Dialogue_2 to display dialog "Type formula
Use ';' to separate statements, e.g.
set x to 2; x+x" default answer ""
--trap error if user clicks "Cancel"
on error errorMsg
error errorMsg
end try
set Formula to text returned of Dialogue_2
--replace all semi-colons with returns
set AppleScript's text item delimiters to {yourDelim}
set Formula to every text item of Formula
set AppleScript's text item delimiters to {return}
set Formula to Formula as text
set AppleScript's text item delimiters to {""}
try
set total to (run script Formula)
--trap any errors in processing script
on error errorMsg
error errorMsg & return & return & Formula
end try
======================================================================
HTH
has