Name: CHOOSE Shortest: CHO
Family: Command Category: Data Manipulation
Description: Use the CHOOSE command to display the following types of menus: bar with a pull-down, check-box, pop-up, sort check-box, vertical, or WHERE builder.

Syntax

CHOOSE syntax diagram

Options

AT CENTER
Displays the menu at the center of the screen.

AT CENTER scrncol
Positions the menu centered horizontally at the specified column.

AT scrnrow CENTER
Positions the menu centered vertically at the specified row.

AT scrnrow scrncol
Specifies a location on screen to display the menu. For scrnrow, an integer between 1 and 25 indicates the screen line on which the menu is displayed. For scrncol, an integer between 1 and 79 indicates the screen column. You can specify scrncol for pop-up, check-box, or sort check-box menus only.

CAPTION 'text'
This option is used in R:BASE for Windows only; displays text in the dialog box titlebar.

CHKBOX
Displays a check-box menu.

CHKSORT
Displays a sort check-box menu.

colname
Specifies a 1 to 18 character column name. In a command, you can enter #c, where #c is the column number shown when the columns are listed with the LIST TABLES command. In an SQL command, a column name can be preceded by a table or correlation name and a period (tblname.colname).

#COLUMNS IN tblview
Displays a pop-up menu containing all columns in the specified table or view and stores the chosen column name in the variable varname.

#LIST (new option added in 6.5++)

#DATABASE
Displays a pop-up menu containing all databases in the current directory, and stores the chosen database name in the variable varname.

DISTINCT
Suppresses the display of duplicate rows.

(expression)
Determines a value using a text or arithmetic formula. The expression can include other columns from the table, constant values, functions, or system variables such as #date, #time, and #pi.

FORMATTED
This options displays the Choose box using a monospace font.

#FORMS
Displays a pop-up menu containing all forms in the open database and stores the chosen form name in the variable varname.

FROM tblname
Specifies the table name.

#GLOBAL
Displays a pop-up menu containing currently defined global variables and stores the chosen variable name in the variable varname.

IN procfile
Specifies the name of a procedure file. A procedure file is a compiled binary file that contains stored menu, screen, and command blocks. Include a drive and path name if the procedure file is not on the current drive and directory.

INITPOS m n
R:BASE for DOS only. Allows you to specify the initially selected menu item. If only m is specified it controls vertical position. If both m and n are specified then m is horizontal position and n is vertical.

#LABELS
Displays a pop-up menu containing all labels in the open database and stores the chosen label name in the variable varname.

#LFILES IN filespec
Displays all files in the current directory in a pop-up list, unless the IN filespec option is specified. In this latter case, the user may specify a filespec such as *.MSG, and R:BASE will display a pop-up list of all files in the specified directory with the .MSG extension. The chosen file name is stored in the variable varname.

LINES n
This option is used with R:BASE for Windows only; determines the number of lines, n, to display in the listbox. The default is 5.

menuname
A user-defined menu can be stored either in an ASCII disk file or as a menu block in an R:BASE procedure file created by CodeLock or Application Express. If procfile is used, menuname refers to a procfile menu block. If procfile is not used, menunamespecifies an ASCII disk file containing the menu to be displayed.

CHKBOX n
n is an optional positive integer specifying the maximum number of options on that menu that can be checked. If n is zero or is greater than the number of menu options, all options can be checked. If n is unspecified, the default value is zero. The maximum value of n is 9999.

ORDER BY clause
Sorts rows of data. For more information, see the "ORDER BY" entry.

#REPORTS
Displays a pop-up menu containing all reports in the open database and stores the chosen report name in the variable varname.

,retcol
Specifies the column whose value is returned into the variable varname (TEXT datatype) . The column does not have to be one of the columns displayed in the menu.

#TABLES
Displays a pop-up menu containing all tables in the open database and stores the chosen table name in the variable varname.

#TBLVIEWS
Displays a pop-up menu containing all tables and views in the open database and stores the chosen table or view name in the variable varname.

TITLE 'title'
Displays a title in the dialog box.

#VALUES FOR
Displays a pop-up menu containing values from the specified column or expression and table. Use the (expression) option to display more than one column from the table in the menu, such as (colname1 & colname2).

varname FROM
Returns a single value into varname if the menu is vertical or pop-up. In a bar menu with a pull-down, check-box, or sort check-box menu, the variable contains one or more values, separated by a comma (or the current delimiter). Do not predefine the variable; the CHOOSE command defines the variable with its proper data type.

#VIEWS
Displays a pop-up menu containing all views in the open database and stores the chosen view name in the variable varname.

WHERE clause
Limits rows of data. For more information, see the "WHERE" entry.

#WHERE IN tblview
Opens the WHERE builder for you to enter conditions for the columns in the specified table or view; stores the entire WHERE clause in the variable varname.

About the CHOOSE Command

R:BASE creates and displays the following types of menus: check-box, pop-up, sort check-box, and WHERE builder. You must create a bar with a pull-down or a vertical menu in a menu file before you can display it.

Database Access Rights with CHOOSE

When access rights for a table or view have been assigned using the GRANT command, CHOOSE requires that the user have SELECT rights to a table or view before it is displayed in the list. The command or procedure file using the menu must include commands that check user identifiers before executing the menu option. For example, if a menu option allows a table to be edited, the command file must prompt users for their user identifier before it allows them to edit the table.

Variables in the CHOOSE Command

R:BASE waits for a menu selection to be entered from the keyboard, and stores the keyboard entry in a designated variable that can be referenced in subsequent processing.

Assigning Data Types

Variables in a bar with a pull-down, check-box, pop-up, sort check-box, or WHERE builder menu are automatically defined as a TEXT data type and filled with the exact wording of the menu choice. Variables in vertical menus are automatically defined as an INTEGER data type and contain the menu-option number. Do not use a variable in a CHOOSE command if its data type is already assigned.

Capturing [Esc]

You can capture [Esc] in a variable. For a bar with a pull-down, check-box, pop-up, sort check-box, or WHERE builder menu, [Esc] stores the string [ESC]. For a vertical menu, [Esc] stores the value 0.

Variables Containing Multiple Items

The CHOOSE variable can contain multiple items in a bar with pull-down, check-box, or sort check-box menus. The items are separated with a comma (or the current delimiter). Do not include the delimiter in menu options.

In a bar with a pull-down menu, the first item in the variable is a text number corresponding to the position of the option on the bar menu, and the second item is the option chosen from the secondary menu.

When a menu type allows multiple options, you can use the SSUB SuperMath function or a vector variable to extract individual parts for checking.

Variables Containing Leading Blank Spaces

The resulting variable (always as TEXT) will be left justified without the leading spaces.

Menu Blocks

A menu block is a menu definition stored in a procedure file. A menu block defines a single menu. A menu block uses the same basic format as a menu definition stored in an ASCII file, but the first line contains the $MENU block identifier.

The options for CHOOSE that begin with the number sign (#) are pop-up menus. These options-except for #VALUES and #WHERE-can be used as menu choices in a menu block to create any of the other menu types.

$MENU 
menuname
COLUMN |Menu Title|
|Menu choice 1| |Option description1|
|Menu choice 2| |Option description2|
|Menu choice 3| |Option description3|
ENDC

In the above example, the word COLUMN in the third command line would produce a vertical menu. The table below lists the description to use to produce the available menu types.

Enter... To create a...
CHKBOX Check-box menu
CHKSORT Sort check-box menu
COLUMN Vertical menu
POPUP Pop-up menu
PULLDOWN Bar with a pull-down menu

Define the contents of the menu in the lines that follow in the block. Enclose each line (menu item) with the pipe symbol ( | ), [ALT] + 0124.

An ENDC line defines the end of the menu definition. Do not include comments within a menu block-R:BASE reads them as invalid data.

ASCII Menu Files

You can also store a menu definition as an ASCII file. Below is an example of a vertical and a bar with a pull-down menu:

Vertical Menu

menuname
COLUMN |Menu Title|
|Menu choice 1| |Option description|
|Menu choice 2|
|Menu choice 3|
ENDC

An ENDC line defines the end of the menu definition. Do not include comments within a menu block-R:BASE reads them as invalid data.

Bar with a Pull-Down Menu

Menu.mnu
PullDown
|Option 1| |Menu Message|
|Option 2| |Menu Message|
|Exit| |Menu Message|
ENDC
POPUP
|Pick 1| |Menu Message|
|Pick 2| |Menu Message|
ENDC
POPUP
|PPick 1| |Menu Message|
|PPick 2| |Menu Message|
ENDC
ENDC

Examples

The following command searches the COMPPROC.APX procedure file for the mainmenu menu block, displays the menu on screen, and waits for entry from the keyboard. Once you choose a menu option, it is stored in the vchoice global variable.

CHOOSE vchoice FROM mainmenu IN compproc.apx

The first command line in the following example displays a menu on the fifth line of the window, listing databases in the current drive and directory. The database name you choose is entered into the dbnamevariable. The second command line uses dbname as an ampersand variable to open the database.

CHOOSE dbname FROM #DATABASE AT 5
CONNECT &dbname

The following command lines choose columns from the transmastertable to display from a check-box menu, and from a sort check-box menu, columns to sort by. The check-box menu and sort check-box menu list columns from the transmaster table. The CHOOSE ampersand variables complete the SELECT command.

CHOOSE vcols FROM #COLUMNS IN transmaster CHKBOX
CHOOSE vsort FROM #COLUMNS IN transmaster CHKSORT
SELECT &vcols FROM transmaster ORDER BY &vsort

The following command displays the twodim bar menu (stored in ASCII file TWODIM.MMM) with pull-down menus from each option on the bar.

CHOOSE voptions FROM twodim.mmm

The following command lines show how to move two values stored in one variable into separate variables. For example, when a pull-down menu item is chosen, the bar menu choice and the pull-down choice are stored in voptions, separated by the current delimiter character (the comma is the default delimiter character). If the bar menu option is the first option on the bar menu and the pull-down option is a form named tranform, voptions will contain 1,tranform. To use these two options, use the two values from the voptions variable. The SSUB function moves the value of one item from the variable containing multiple items into another variable. In the example below, the first SET VARIABLE command moves the first item (the bar menu option) into voption1; the second moves the second item (the pull-down menu option) into voption2.

SET VARIABLE voption1 = (SSUB(.voptions,1))
SET VARIABLE voption2 = (SSUB(.voptions,2))

The following command displays a menu that lists company names from the customer table. The listing is ordered alphabetically, and each company is listed once.

CHOOSE vcompany FROM #VALUES FOR DISTINCT company +
FROM customer ORDER BY company

The following command displays a pop-up menu containing the file names of all the files in the current directory that have a file extension of .MSG.

CHOOSE V1 FROM #LFILES IN *.MSG

The following example displays a menu with the title "Company Name and Location." The vchoice variable obtains a value from the custid column although that column is not accessible from the menu.

CHOOSE vchoice from #VALUES FOR (LJS(company,40) & +
custcity + ','& custstate), custid FROM customer AT 7,3 +
TITLE 'Company Name and Location'

Using the following menu definition (saved as Example.MNU):

$MENU
PULLDOWN
 |tables| 
 |views| 
 |forms| 
 |reports| 
 |labels|
ENDC
POPUP
#tables
ENDC
POPUP
#views
ENDC
POPUP
#forms
ENDC
POPUP
#reports
ENDC
POPUP
#labels
ENDC

You could use the following command sets with the CONCOMP sample database.

This will display a normal menu:

CLEAR ALL VARIABLES
CONNect CONCOMP
CLS
CHOOSE vPick1 FROM Example.MNU AT CENTER CENTER

This will highlight the initial menu pick #3, i.e. Forms:

CLEAR ALL VARIABLES
CONNect CONCOMP
CLS
CHOOSE vPick1 FROM Example.MNU AT CENTER CENTER INITPOS 3

This will highlight the initial menu pick #3, i.e. Forms, and then highlight the #4 option from a pulldown menu, i.e. tranform:

CLEAR ALL VARIABLES
CONNect CONCOMP
CLS
CHOOSE vPick1 FROM Example.MNU AT CENTER CENTER INITPOS 3 4