2010-11-12 43 views
0

我已經作出,其接受半徑作爲輸入從用戶和基於輸入計算並顯示圓的面積的簡單腳本應用:簡單腳本未按預期

-- 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
repeat until class of radius is integer or class of radius is real 
+0

奏效......感謝名單:) – Devarshi 2010-11-15 12:06:03