ppt lesson 09

Post on 25-Jun-2015

1.064 Views

Category:

Technology

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

Microsoft Visual Basic 2005 BASICS

Lesson 9

Nested If Statements and Radio Buttons

Microsoft Visual Basic 2005 BASICS 2

Objectives

Use nested If statements. Use radio buttons. Use the Form Load event. Use the Select Case statement.

Microsoft Visual Basic 2005 BASICS 3

Using Nested If Statements

Nested If statement An If statement placed inside another If

statement When using nested If statements

It is important that you properly indent the code.

Microsoft Visual Basic 2005 BASICS 4

Using Nested If Statements (cont.)

Microsoft Visual Basic 2005 BASICS 5

Using Nested If Statements (cont.)

Microsoft Visual Basic 2005 BASICS 6

Using Radio Buttons

Radio buttons are similar to check boxes with one important difference. Radio buttons appear in groups. Only one button can be selected at a time.

Microsoft Visual Basic 2005 BASICS 7

Using Radio Buttons (cont.)

Using radio buttons Create a GroupBox to group the radio

buttons. Create the radio buttons in the GroupBox. Write code to use the radio buttons.

Microsoft Visual Basic 2005 BASICS 8

Using Radio Buttons (cont.)

Microsoft Visual Basic 2005 BASICS 9

Creating a GroupBox Control

GroupBox control Container for other controls

Controls that you place inside a GroupBox are treated as one unit.

Option group Radio buttons in a GroupBox

GroupBox most important properties (Name) and Text

Microsoft Visual Basic 2005 BASICS 10

Creating a GroupBox Control (cont.)

Microsoft Visual Basic 2005 BASICS 11

Creating a GroupBox Control (cont.)

Microsoft Visual Basic 2005 BASICS 12

Creating Radio Buttons in the GroupBox

Once the GroupBox is created Add radio

buttons to the GroupBox.

Microsoft Visual Basic 2005 BASICS 13

Setting Radio Button Name and Text Properties

Radio buttons need to be named appropriately. Use the Name property

The Text property Specifies the message for the attached

label

Microsoft Visual Basic 2005 BASICS 14

Setting Radio Button Name and Text Properties (cont.)

Microsoft Visual Basic 2005 BASICS 15

Adding Code to the Radio Buttons

Coding radio buttons Requires that you think in an event-driven

way Use form-level variables as the scope.

To keep track of the option that has been selected

Microsoft Visual Basic 2005 BASICS 16

Adding Code to the Radio Buttons (cont.)

Microsoft Visual Basic 2005 BASICS 17

Processing the Data

The final step Calculate the result and create the output.

Microsoft Visual Basic 2005 BASICS 18

Using a Form Load Event Procedure

Set the Checked property to True. The radio button is selected.

When a form is loaded and opened A special event called a Load event is

triggered. You can write an event procedure for the

form’s Load event.

Microsoft Visual Basic 2005 BASICS 19

Using Select Case

In a Select Case statement You specify a variable to test. You then list a number of cases for which

you want to test. The first line in a Select Case

statement Specifies the data involved in the decision

Microsoft Visual Basic 2005 BASICS 20

Using Select Case (cont.)

You can use conditional operators in a Case statement.

Microsoft Visual Basic 2005 BASICS 21

Summary

If statements can be nested to make additional decisions within the code of the If statement.

It is important to indent the code in a nested If statement to make the code readable.

Microsoft Visual Basic 2005 BASICS 22

Summary (cont.)

Each If statement within a nested If statement must end with the End If statement.

Radio buttons appear in groups. Only one radio button in the group can be selected at a time.

Radio buttons are sometimes called option buttons.

Microsoft Visual Basic 2005 BASICS 23

Summary (cont.)

The first step in creating a group of radio buttons is to create a GroupBox control to contain the radio buttons. The controls within a GroupBox are treated as one unit.

The Text property of a GroupBox control specifies the text that appears at the top of the GroupBox.

Microsoft Visual Basic 2005 BASICS 24

Summary (cont.)

To associate a radio button with a GroupBox, click the RadioButton tool only once and draw the radio button in the GroupBox. If you double-click to create a radio button, it will not associate itself with the GroupBox.

The Text property of a GroupBox control specifies the text that appears on the label attached to the radio button.

Microsoft Visual Basic 2005 BASICS 25

Summary (cont.)

Coding radio buttons involves using form-level variables that carry values that reflect the selected radio button.

A form’s Load event procedure is executed each time a form is loaded and opened by the program.

Microsoft Visual Basic 2005 BASICS 26

Summary (cont.)

The Select Case statement allows you to make multi-way selections. The Case statements in a Select Case can test a range or use conditional operators.

Conditional operators in a Case statement must include the Is keyword.

As a default, the Case Else statement is applied if no other Case is true.

top related