I have made a simple script application which accepts radius as input from user and calculates and displays area of circle based on input:
-- 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 ente开发者_如何转开发rs 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
When I executed the above script and entered some text for the first time, it again asked me to enter the radius, this time I entered some number and it displayed the area of circle but it again started asking for radius as input from user.
Can anyone suggest me where I am wrong in the above script?
Thanks,
Miraaj
repeat until class of radius is integer or class of radius is real
精彩评论