Re: Propmpting user to enter Variables
Re: Propmpting user to enter Variables
- Subject: Re: Propmpting user to enter Variables
- From: has <email@hidden>
- Date: Fri, 13 May 2005 17:20:30 +0100
francois houle wrote:
>I have four variables that the user gets prmpted for when a script begins...
>However I have added a section aftet hat to check if any of the fields are
>left empty, and if so it would offer then to either cancel the script or try
>to enter the variables again...
>
>Just can't find how to re-prompt the user to enter those variables... And
>obviously they would need to get the Error prompt on any attemp...
Define your own command to display an input dialog and validate the user input before returning a valid value or asking the user to try again. Example:
-------
on getUserInput(messageTxt)
(* Ask the user to input a non-empty string.
messageTxt : string -- the message to display in the input dialog
Result : string -- the user-inputted data
Notes: raises error number -128 if user cancels.
*)
set txt to text returned of (display dialog messageTxt default answer "")
if txt is "" then
display dialog "You must supply a value." buttons {"Cancel", "Retry"} default button 2 with icon caution
return getUserInput(messageTxt)
else
return txt
end if
end getUserInput
set var1 to getUserInput("enter this info here")
set var2 to getUserInput("enter that info here")
set var3 to getUserInput("enter this info 2 here")
set var4 to getUserInput("enter that info 2 here")
-------
As well as simplifying your code it also provides the user with more immediate feedback and doesn't require them to re-input all values whenever they make a mistake.
HTH
has
--
http://freespace.virgin.net/hamish.sanderson/
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden