Skip to content

Combobox Exercise

Exercise: Creating a Point-of-Sale Menu

Tags

This example uses two tags. The first tag will be named Price with the data type set to REAL (FLOAT32). The second tag will be named Index with the data type set to INT (INT16) and the initial value set to -1.

Recipe

This example will utilize the Recipe Editor. Create a new recipe named Smoothies. Add Index as the Record ID Tag. Add four different parameter bindings: Ingredient 1, Ingredient 2, Ingredient 3, and Price. Create three different records with three different ingredients and prices for each one.

Bind a tag to each parameter to prevent an error warning. The tags don't have to be used.

Script

This example also utilizes the Script Editor. Create a script named Check Price with the Running Type set to Periodic.

Check Price Code::

if (tag.read("Index") != -1) {
	tag.write("Price", recipe.getParameter("Smoothies", tag.read("Index"), 3));
}

This script checks if the Index tag is NOT -1 and writes the corresponding price from the record ID to the Price tag.

Project Setup

Set up the project to look like the below image. The project utilizes the combobox object, numeric label object, and a few label objects.

ComboBox

For the combobox object, bind the Index tag to the Index field. Add three choices: Berry, Strawberry-Banana, and Peanut Butter. These correspond to the record names in the recipe.

Numeric Label

For the numeric label object, bind the Price tag to the Value field. In the Format section, set the Decimal Places to 2, enable Use Leading Zeros, and set Leading Zeros to 1. Set the Prefix to Total Price: $.

Label

For the label object that displays Confirm, add two On Press actions: Set Tag Value for the Index tag to -1.0 and Set Tag Value for the Price tag to 0.0.

Simulator

To test the exercise, open the Simulator.

In the combobox, select an item. The price will correspond to the Price tag from the recipe.

After the Confirm button is pressed, the combobox selection is reset, and the price is also reset.