Inserting Choice Controls in Edit Table Cells

Revision as of 22:07, 16 July 2007 by Lchrisman (Talk | contribs) (Review of choice function)

Mini-tutorial: Choice controls in edit table cells

A new feature in Analytica 4.0 is the ability to present pulldown controls in the cells of an edit table. Using pulldowns in this fashion can provide a convenience to the users of your model, and ensure that they select only valid values for cell values. The following screenshot demonstrates the use of pulldowns in an edit table:

Power plant table with pulldowns.JPG

This short mini-tutorial takes you step-by-step through a simple example to produce the table shown.

How it is done

The edit table displayed above actually contains the following cell contents:

Edit table with choice in edit mode.JPG

When the edit table is viewed from edit mode (i.e., by a model builder), we see this. When the same table is viewed from browse mode (i.e., by the user of the model), the controls display. For the table to be changeable when viewed in browse mode, the table must have an input node. So, the basic steps are to create the indexes containing the list of valid choices for each pulldown, create the edit table, make an input node for the table, and finally populate the edit table with calls to the choice function, where appropriate. Later in the tutorial, we'll also learn how to configure the table so that if new rows are added, the default cell contents for the new row (with choice controls) are automatically inserted.

Identifying Possible Selections

1. Start Analytica 4.0 and fill in the object window:

ECTut object window.JPG

2. Close the object window

3. We'll begin by defining the possible Plant types. Drag an index to the diagram and title it: Plant Type

4. Press Expr.jpg to edit the definition, and in the definition type pulldown, select "List of labels".

5. Fill in the possible plant types as shown (pressing down-arrow from the last cell to append a new cell each time):

Plant types.JPG

6. Repeat steps 3-5 to define an index County:

County.JPG

7. Next, create an index named Boolean having the values [False, True]. In this case, instead of using a list-of-labels, we are going to use a "List". This means that cells in the list contains the identifiers False and True, rather than the string "False" and "True". These evaluate to 0 and 1 respectively. This will allow the text "False" and "True" to display in the pulldown, but when the Choice expression is evaluated, it will evaluate to the numeric values of 0 or 1. If we were to define as a list of labels, they would evaluate to the text "False" or "True". Drag an index node to the diagram, title it "Boolean", and select "List" for the definition type. Enter False, press downarrow, and enter True.

Boolean_index.JPG

At this point, we have specified the possible values for each choice control.

Understanding the Choice function

You may have previously used the Choice function to create pulldowns. Here, we'll review this briefly before we actually insert these into the edit table cells.

8. Drag a variable node to the diagram, name it "Select Plant Type". In the definition type pulldown, select "Choice".

9. Fill in the parameters as shown:

Choice function finder.JPG

For the I parameter, we've specifies the Plant_type index that we defined in Steps 3-5. These are the possible choices. We've tentatively set n=1 to select the first item in the list (which is valid until the user actually selects something different in the control). And finally we've set inclAll to false. This third parameter turns off the "All" option so the user does not have the option of selecting every plant type. When placing pull-down controls inside edit tables, you will probably not want "All" to be an option.

10. Press OK. In the attribute dialog, a choice pulldown appears.

11. Click on the pop-up (which currently displays "Natural Gas") and select "Nuclear". Then, change the definition-type pulldown to expr (Expression). Notice that the following definition appears:

Choice(Plant_type,4,False)

Notice that the second parameter has changed from 1 to 4 as a result of selecting "Nuclear". Analytica automatically re-writes the definition of a Choice function when the user selects a new option.

Comments


You are not allowed to post comments.