{"identifier":31208,"topic":"Commands","name":"ask","text":"<code>ask <i>text1<\/i> <\/code>[<code>with <i>text2<\/i><\/code> ]<u><code> <br><br>\n\n <\/u>ask password <\/code>[<code>clear<\/code>]<code> <i>text1<\/i> <\/code>[<code>with <i>text2<\/i><\/code> ] <code>ask file <i>text1<\/i> <\/code>[<code>with <i>fileName<\/i><\/code> ]  <br><br>\n\n The<code> ask <\/code>command displays a <b>question<\/b> (<i><code>text1<\/i><\/code> ) in a dialog box along with a text box where the user can type a reply. The<code> ask <\/code>dialog automatically provides the OK and Cancel buttons. <br><br>\n\n You can supply a <b>default reply<\/b> using the<code> with <i>text2<\/i> <\/code>option. The default text appears highlighted in the text box. <br>\n<br>\n<code>Ask<\/code> returns the text entered by the user, if any, in the local variable<code> it<\/code>. If the user clicks Cancel,<code> ask <\/code>places<code> empty <\/code>in<code> it<\/code>. <code><pre>\n<\/pre><\/code>\n<code>Ask <\/code>also sets the HyperTalk function<code> the result <\/code>to<code> empty <\/code>if the user clicks OK or to<code> Cancel <\/code>if the user clicks Cancel.  (So you can use the value of<code> the result <\/code>to determine whether the user provides an empty string or clicks Cancel.)  You must check<code> the result <\/code>in the statement immediately after the<code> ask <\/code>command. <br>\n","related":{"30026":"answer"},"examples":"-- userName is a global variable set up by the Home stack:\nask \"Enter your name:\" with userName \n\nask \"What time of day?\" with \"Noon\"\nif the result is \"Cancel\" then\n   -- the user clicked the Cancel button\nelse if it is empty then\n   -- the user clicked OK with no answer\nelse\n   -- the user clicked OK and provided an answer\nend if\n\nask password \"Enter your password:\"\nif it is in card field \"passwords\" then allowAccess\nelse go Home\n\nask file \"Save the file as:\" with \"Untitled\"","demo":"on mouseUp\n   -- convert some arbitrary seconds to the date  \n   -- to get the date format as set for the system.\n   put \"1838246400\" into someSeconds\n   convert someSeconds to short date\n   <br><br>\n\n   <b>ask<\/b> \"Enter your birthday:\" with someSeconds\n   if the result is \"Cancel\" then answer \"You clicked Cancel.\"\n   else\n     put convertBirthDayToDays(it) into numberOfDays\n     if numberOfDays is not empty\n     then answer \"You are\" && numberOfDays && \"days old.\"\n   end if\n end mouseUp\n <br><br>\n\n function convertBirthDayToDays birthDay\n   convert birthDay to seconds\n   if the result is \"invalid date\" then beep\n   else\n     convert the date to seconds\n     put it - birthDay into secondsOld\n     return secondsOld \/ 86400 -- 86400 is the number of seconds in a day\n   end if\n end convertBirthDayToDays\n ","debug":{"9":["ask text1 [with text"],"10":["Ask returns the text"]}}