Presentation is loading. Please wait.

Presentation is loading. Please wait.

Visual Basic.NET BASICS Lesson 9 Nested If Statements and Radio Buttons.

Similar presentations


Presentation on theme: "Visual Basic.NET BASICS Lesson 9 Nested If Statements and Radio Buttons."— Presentation transcript:

1 Visual Basic.NET BASICS Lesson 9 Nested If Statements and Radio Buttons

2 2 Objectives Use nested If statements. Use radio buttons. Use the form Load event. Use the Select Case statement.

3 3 Using Nested If Statements When you place an If statement inside another If statement, the If statement inside is called a nested If statement. When using nested If statements, it is important that you properly indent the code.

4 4 Using Radio Buttons Radio buttons are similar to check boxes with one important difference.  Radio Buttons appear in groups, and only one button in the group can be selected at a time. To successfully use radio buttons, there are three steps involved:  Create a GroupBox to group the radio buttons.  Create the radio buttons in the GroupBox.  Write code to use the radio buttons.

5 5 Creating a GroupBox Control A GroupBox control is a container for other controls. The controls that you place inside a GroupBox are treated as one unit. Radio buttons in a GroupBox are sometimes referred to as an option group.

6 6 Creating Radio Buttons in the GroupBox Now that the GroupBox is created, the next step is to add radio buttons to the GroupBox. Like other controls, radio buttons need to be named appropriately using the Name property.

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

8 8 Using a Form Load Event Procedure By setting the Checked property of a radio button to True, the radio button is selected. When a form is loaded and opened by the program, a special event called a Load event is triggered. Like other events, you can write an event procedure for the form’s Load event.

9 9 Using Select Case In a Select Case statement, you specify a variable to test and then list a number of cases for which you want to test. The first line in a Select Case statement specifies the piece of data that is involved in the decision. You can use conditional operators in a Case statement as well.

10 10 Setting Additional Properties The BackColor property sets the form’s background color. The Location property allows you to specify the location of an object using X and Y coordinates.

11 11 Summary If statements can be nested to make addi- tional 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. 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.

12 12 Summary (continued) 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.

13 13 Summary (continued) To associate a radio button with a GroupBox, you must 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 radio button specifies the text that appears on the label attached to the radio button.

14 14 Summary (continued) Coding radio buttons involves using form- level variables that carry values that reflect the selected radio. A form’s Load event procedure is executed each time a form is loaded and opened by the program.

15 15 Summary (continued) The Select Case statement allows you to make multi-way selections. The Case state- ments 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.


Download ppt "Visual Basic.NET BASICS Lesson 9 Nested If Statements and Radio Buttons."

Similar presentations


Ads by Google