Chapter 3- Data Types and Operators Boolean Expressions Page 2 3 4

Introduction

The If Statement Page 2 3 4 5 6 7 8 9
Arithmetic Operations Page 2 3 4 5 6 Boolean Operators and Nested If Statements Page 2 3 4 5 6 7
Events and Sequential Processing Page 2 3 4 5 More Examples Page 2 3 4 5 6 7 8 9 10 11 12
Datatypes and Conversions Page 2 3 4 5 6 7 Using Check Box and Option Controls Page 2 3 4 5 6 7 8 9 10
Variable Declarations - Local and Global Page 2 3 4 5 6 7 8 9 10 11 12 13 14 15 Exercises Page 2 3 4 5 6 7 8
Chapter 4- Selection Statements Review Questions
Introduction

4-7: Check Box and Option Controls

Exercise 4-6: Global Classics Cinema continued ...

The user is now able to select one or more of the ticket types. Checking one of the checkboxes, Adult, Child, or Senior, should set the ticket quantity to 1 and make the corresponding row of interface objects visible (i.e. the - and + buttons, the quantity textbox, the ticket price label etc.). Unchecking one of the checkboxes should set the corresponding ticket quantity to 0 and make the row of interface objects invisible. In both cases the price for that ticket type and the total price should be calculated.

Thus, taking the adult ticket checkbox as an example, the click event code should

This description has implied use of at least four pieces of data. There is the quantity of adult tickets, the price of the adult tickets (i.e. quantity multiplied by the price of each ticket), the price of each ticket, and the grand total of the price (which might include prices for child and, or senior tickets).

We need to consider how this data is stored and the values modified as the user interacts with the program. Which of these quantities should be variables and which should be constants? Lets give them names - adultQty, adultCost, adultPriceTotal, totalPrice.

The next issue to decide is where these variable(s) and constant(s) should be declared - globally or locally. The key consideration is to decide which events need to use the values. If any value is needed in only one Sub event then it should be declared locally within that event.

It should be clear to you that in addition to the checkbox click or change event the adultQty variable needs to be changed in both the minus and plus command buttons. Thus this variable should be declared globally. In addition the adult price total and the grand total of the price should be changed whenever the user clicks a plus or minus command button, and whenever the user selects the adult ticket type checkbox. Thus these two variables should also be declared globally.