简单脚本无法按预期工作

时间:2010-11-12 15:36:24

标签: applescript

我制作了一个简单的脚本应用程序,它接受来自用户的半径输入,并根据输入计算并显示圆的面积:

-- initializing radius variable to some text
set radius to "Some text"

repeat until class of radius is number

-- asking user for radius
display dialog "Enter radius: " default answer "" buttons {"Done"} default button 1
set userInput to text returned of result

-- try to check if user enters radius as number
try

-- converting input from user to number 
set radius to userInput as number

-- if input is found as number then below code is executed
-- obtaining radius from handler
set circleArea to calculateCircleArea(radius)

-- displaying radius and area of circle obtained to user
display dialog "Circle area for radius: " & radius & " is: " & circleArea buttons {"OK"} default button 1
end try
end repeat

-- handler definition
on calculateCircleArea(parameterRadius)
set areaOfCircle to pi * (parameterRadius ^ 2)
end calculateCircleArea

当我执行上面的脚本并第一次输入一些文本时,它再次要求我输入半径,这次我输入了一个数字并显示了圆形区域,但它又开始要求输入半径作为输入用户。

在上面的剧本中,有人能建议我说错了吗?

谢谢,

Miraaj

1 个答案:

答案 0 :(得分:1)

repeat until class of radius is integer or class of radius is real