2014-01-10 54 views
2

我在連續使用少於或大於運算符的AppleScript中出現錯誤。我可能沒有很好地解釋,所以我會發布代碼。AppleScript少於數字或大於數字

**set good to false** 

**repeat until good = true** 
set oneTen to the text returned of (display dialog "Pick a number from 1 through 10" default answer "" buttons {"OK"} default button 1) as number 

if oneTen is less than 0 then 
    display dialog "below" buttons {""} default button 1 
else if oneTen is greater than 10 then 
    display dialog "above" buttons {""} default button 1 
else 
    set good to true 
end if 
**end repeat** 

我試圖從提示輸入,並保持用戶進入低於0或10以上任何你可以張貼一些代碼來做到這一點呢?

我想要類似這樣的東西。

**set oneTen to the text returned of (display dialog "Pick a number from 1 through 10" default answer "" buttons {"OK"} default button 1) as number** 

**if oneTen is less than 0 or greater than 10 then** 

**-- make them do the prompt again** 

**end if** 
+0

我忘了說。謝謝!! – XQLRSZ

回答

2

嘗試:

repeat 
    set oneTen to the text returned of (display dialog "Pick a number from 1 through 10" default answer "" buttons {"OK"} default button 1) as number 

    if oneTen is less than 0 then 
     display dialog "below" buttons {""} default button 1 
    else if oneTen is greater than 10 then 
     display dialog "above" buttons {""} default button 1 
    else 
     exit repeat 
    end if 
end repeat 
+0

這工作正如我想要的一樣!我甚至可以添加到它,所以我可以擴展我的代碼。謝謝!另外,感謝您的快速回答! – XQLRSZ