Skip to content

Combobox Exercise

Exercise

Exercise: Creating a Point-of-Sale Menu

Please follow the below exercise to understand ComboBox functionality.

Configuration

The following configuration is used to set up this exercise.

Tag Configuration

  1. Create the following tags:
    1. Price
      • Data type: Real (FLOAT32)
      • Initial value: 0.0
    2. Index
      • Data type: INT (INT16)
      • Initial value: -1

Recipe Configuration

  1. Create the following recipe database:
    1. Smoothies
      • Record ID Tag: Index
      • Parameter bindings: Ingredient 1, Ingredient 2, Ingredient 3, 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 Configuration

  1. Create the following script:
    1. Check Price
      • Running type: Periodic

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 Configuration

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

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

  1. For the numeric display object, bind the Price tag to the value property. In the format section, set the decimal places to 2, enable use leading zeros, and set leading zeros to 1. Set the prefix property to "Total Price: $".

  1. For the text display object that displays "Confirm", add two On Press action properties: Set Tag Value for the Index tag to -1.0 and Set Tag Value for the Price tag to 0.0.

Project Deployment

  1. Click Tools > Launch Simulator to launch the Canvas Simulator.

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

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