Alyce May 9, 2011
=Prompt= [[toc]] ---- ==What is a PROMPT?== A is a very helpful, special dialog. Use it to ask a question and get an answer from the user. Here is an example of a prompt: [[image:prompt.gif]] ==Syntax for PROMPT== [[code format="lb"]] PROMPT "string expression"; responseVar$ [[code]] As it would look in a program: [[code format="lb"]] prompt "How many would you like to purchase?";howMany [[code]] ==Description== The helpfile gives this description: //The PROMPT statement opens a dialog box, displays the message contained in "string expression", and waits for the user to type a response in the textbox and press the ENTER key, or press the OK or Cancel button on the dialog. The entered information is placed in responseVar$. If Cancel is pressed, then a string of zero length is returned. If responseVar$ is set to some string value before PROMPT is executed, then that value will become the "default" or suggested response that is displayed in the contained in the PROMPT dialog. This means that when the dialog is opened, the contents of responseVar$ will already be entered as a response for the user, who then has the option to either type over that 'default' response, or to press 'Return' and accept it.// ==Receiver Variable== If we fill the "howMany" variable before issuing a PROMPT command, the code looks like this: [[code format="lb"]] howMany=4 prompt "How many would you like to purchase?";howMany [[code]] The prompt then looks like this, with the number 4 in the textbox. If the user presses ENTER at this point, he accepts that default answer. [[image:prompt2.gif]] ==Caption for the Prompt Window== If the string of text used for the prompt message has no carriage return character - chr$(13) - then the caption on the prompt dialog is blank and the string expression is the message displayed inside the dialog box. If the string expression includes a Chr$(13) then the part of the string before Chr$(13) is used as the title for the prompt dialog, and the part of the string after Chr$(13) is displayed as the message inside. Here is an example that places the word "Attention!" on the caption of the prompt. [[code format="lb"]] howMany=4 prompt "Attention!" + chr$(13) + "How many?";howMany [[code]] It looks like this: [[image:prompt2.gif]] ==The String Expression== The string expression used in the prompt can be a literal string, a string variable, or a combination. It can consist of several strings that are added together (concatenated.) Some examples: [[code format="lb"]] msg$ = "Select a " + itemType$ msg$ = name$ + color$ msg$ = "Error" + chr$(13) + "Please choose another ";name$ prompt msg$";var [[code]] ==Evaluating Input== When the user dismisses the PROMPT, his answer is contained in the receiver variable. [[code format="lb"]] howMany=4 prompt "Attention!" + chr$(13) + "How many?";howMany if howMany>0 then print "You chose to purchase ";howMany else print "You cancelled the transaction." end if [[code]] ==Receiver Variable Type== The examples we've used so far have a numeric receiver variable. You may use a string, too. Here's an example that uses a string receiver variable and responds to the input: [[code format="lb"]] prompt "Hello!" + chr$(13) + "What is your name?";name$ if name$<>"" then print "It's nice to meet you, ";name$;"." else print "You did not enter a name." end if [[code]]