Monday, December 9, 2019

#1 2019-11-30 12:15:39 pm

Pace514
Member
Registered: 2019-11-19
Posts: 5

My first question

Hi all !! !

Totally new !

I d'ont know if if i'm doing it right but you'll tell me...

Here's a script from Sal Sagohian's book.

I'd like to know why it is not compiling ?

[set low_value to 1
set high_value to 10
repeat
display dialog ("Enter a number between")¬
& low_value & " and " high_value & ":" default answer ""
try
if the text return of the result is not "" then¬
set this_number to¬
the text return of the result as number
if this number is greater or equal to low_value and¬
this number is less than or equal to high_value then
exit repeat
end if
on error
beep
end try
end repeat]

THankS a lot.

Offline

 

#2 2019-11-30 02:49:35 pm

StefanK
Member
From:: St. Gallen, Switzerland
Registered: 2006-10-21
Posts: 11627
Website

Re: My first question

There are a lot of mistakes (apart from the wrong enclosing brackets)

- In the display dialog expression a & is missing before high_value
- It's text returned rather than text return
- It's this_number (with underscore) rather than this number
- It's greater than or equal rather than greater or equal


regards

Stefan

Offline

 

#3 2019-11-30 03:01:06 pm

Nigel Garvey
Moderator
From:: Warwickshire, England
Registered: 2002-11-20
Posts: 5118

Re: My first question

Hi Pace514. Welcome to MacScripter.

When posting here, would you mind giving your posts more descriptive subject lines? Here it could be something like "Script won't compile".

There are a number of copying errors in the code you posted. I imagine it should look like this:

Applescript:

set low_value to 1
set high_value to 10
repeat
   display dialog ("Enter a number between") ¬
       & low_value & " and " & high_value & ":" default answer ""
   try
       if the text returned of the result is not "" then ¬
           set this_number to ¬
               the text returned of the result as number
       if this_number is greater than or equal to low_value and ¬
           this_number is less than or equal to high_value then
           exit repeat
       end if
   on error
       beep
   end try
end repeat

However, from the point of view of not using the 'result' more than once and not getting the 'text returned' value from it more than once, it would be better like this:

Applescript:

set low_value to 1
set high_value to 10
repeat
   set this_number to text returned of (display dialog ("Enter a number between") ¬
       & low_value & " and " & high_value & ":" default answer "")
   if this_number is not "" then
       try
           set this_number to this_number as number
           if this_number is greater than or equal to low_value and ¬
               this_number is less than or equal to high_value then
               exit repeat
           end if
       on error
           beep
       end try
   end if
end repeat


NG

Offline

 

#4 2019-11-30 08:35:54 pm

Pace514
Member
Registered: 2019-11-19
Posts: 5

Re: My first question

Thanks guys !!!

Bad transcription on my side. I'll get used to the english like format.

So, i dont have to put my scripts between brackets ?

see you !

Pace

Offline

 

#5 2019-12-01 03:06:43 am

Nigel Garvey
Moderator
From:: Warwickshire, England
Registered: 2002-11-20
Posts: 5118

Re: My first question

Pace514 wrote:

So, i dont have to put my scripts between brackets ?


Hi Pace.

Not in the scripts themselves. When posting scripts to MacScripter, we have special [applescript] and [/applescript] tags which make them appear as above: in boxes with clickable links which open them in an editor. AppleScript code should be enclosed between these when it's posted here.

AppleScript uses (), {}, and «» brackets for various purposes, but [] brackets shouldn't be used at all in scripts (unless they're required in text, of course!).


NG

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)