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 ...

You should now be able to program the CheckedChanged event for the adult tickets checkbox.

A few more hints:

  1. having changed the value of the adultQty variable either to 1 if the checkbox is checked, or to 0 if the checkbox is unchecked, you need to display that value in the textbox. You will never obtain the ticket quantity from the textbox - you have declared a variable for this purpose; the textbox is used only to display the result. I.e. you will never write:

    adultQty = Convert.ToInteger(txtAdultQty.Text)

  2. having computed the value for the adultCost variable you need to display it in the appropriate textbox; but it should appear with a $ symbol and only two decimal places. You should be able to use the Object Browser to find a function that will convert an input value to a String formatted as currency ... look in the Microsoft.VisualBasic namespace for the Strings module.
  3. also having computed the total cost the value should be displayed in currency format.

Next we should consider how to code the plus and minus command buttons. Their behaviour is not much different from the checkbox event; they should increase or decrease the adultQty variable and recalculate the adultCost and totalCost variables, displaying these new values in the appropriate textboxes.

In addition, however, if the minus button decreases the quantity to 0 the controls should be made invisible and the checkbox itself should be unchecked. Presumably in this case, i.e. the user decreased the quantity of tickets from 1 to 0, they have decided that in fact they don't want any adult tickets.

You should be able to implement the _Click events for these two command buttons now.