Communicating with the User

You will often want to be able to communicate with your user, to ask them questions, allow them to select a folder or file or give them options or information.

LiveCode provides a number of built in dialogs to allow this type of communication, these dialogs are displayed natively on all platforms.

The Answer Dialog

The Answer Dialog

The answer dialog allows you to display information on screen, and optionally allows the user to make a choice from a list of up to seven choices. If no choices are specified then an "OK" button is shown.

The answer command allows you to specify the text and button choices and returns the button that was clicked. You can also specify the window title, as well as an icon to be displayed.

The font, object positions, button order and icon automatically change to reflect the operating system.

Example:

answer question "Do you want to continue?" with "Yes" or "No" or "I don't know"

The Ask Dialog

The Ask Dialog

The ask dialog allows you to ask the user a question where they can type their answer.

The ask command allows you to specify the question, window title and icon. As with the answer dialog the font, object positions, button order and icon automatically change to reflect the operating system.

The ask dialog is shown with "OK" and "Cancel" buttons. If the user clicks "OK" the content of the text box is placed in the it variable and the result function returns empty. If the user cancels the dialog the it variable is set to empty and the result function returns cancel.

Example:

ask "What is your name?"

Note: The it variable is a special local variable that is used  to get the reslt of certain commands such as get, read from file, convert, ask, and answer. The it variable can be used like any other local variable: you can put a value into it, or put it into another container.

File Selector Dialogs

The file selector dialogs allow you to display the system standard dialogs. These dialogs allow the user to select a file or a set of files, select a directory, or specify a name and location to save a file.

The Answer File Dialog

The Answer File Dialog

The answer file command displays a standard file dialog for the user to select a file. You can specify a prompt and an optional defaultPath.

The file path to the file selected by the user is returned in the it variable. If the user cancelled the dialog, the it variable will be empty and "cancel" will be returned by the result function.

Example:

answer file "Select the files you wish to process:"

The Ask File Dialog

The Ask File Dialog

The ask file command displays a standard Save dialog for the user to enter a file name and specify a location. You can specify a prompt and an optional defaultPath.

The file path to the file selected by the user is returned in the it variable. If the user cancelled the dialog, the it variable will be empty and "cancel" will be returned by the result function.

Example:

ask file "Please name the file:"

The Answer Folder Dialog

The Answer Folder Dialog

The answer folder command displays a standard file dialog for the user to choose a folder. You can specify a prompt and an optional defaultPath.

The file path to the file selected by the user is returned in the it variable. If the user cancelled the dialog, the it variable will be empty and "cancel" will be returned by the result function.

Example:

answer folder "Please choose a folder:"

The Answer Color Dialog

The Answer Color Dialog

The answer color command displays the operating system's standard color-selection dialog box, allowing the user to choose a color. You can specify an optional startingColor. If you specify a startingColor, the dialog box displays that color by default.

The color the user chooses is placed in the it variable. If the user cancels the dialog, the it variable is set to empty, and the result function returns "Cancel".

The color is returned in the form of three comma-separated integers between zero and 255, specifying the level of each of red, green, and blue. This format can be used directly to set any color property.

Example:

answer color with "blue"

0 Comments

Add your comment

E-Mail me when someone replies to this comment