SlideShare ist ein Scribd-Unternehmen logo
1 von 26
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.

Weitere ähnliche Inhalte

Was ist angesagt?

Image contro, and format functions in vb
Image contro, and format functions in vbImage contro, and format functions in vb
Image contro, and format functions in vbAmandeep Kaur
 
Chapter 03 - Program Coding and Design
Chapter 03 - Program Coding and DesignChapter 03 - Program Coding and Design
Chapter 03 - Program Coding and Designpatf719
 
Visual basic blackbook 1998
Visual basic blackbook 1998Visual basic blackbook 1998
Visual basic blackbook 1998Speed Cyber Cafe
 

Was ist angesagt? (7)

Active x control
Active x controlActive x control
Active x control
 
Image contro, and format functions in vb
Image contro, and format functions in vbImage contro, and format functions in vb
Image contro, and format functions in vb
 
Chapter 03 - Program Coding and Design
Chapter 03 - Program Coding and DesignChapter 03 - Program Coding and Design
Chapter 03 - Program Coding and Design
 
Intake 38 8
Intake 38 8Intake 38 8
Intake 38 8
 
Visual basic
Visual basicVisual basic
Visual basic
 
Visual basic blackbook 1998
Visual basic blackbook 1998Visual basic blackbook 1998
Visual basic blackbook 1998
 
Vb
VbVb
Vb
 

Andere mochten auch

Andere mochten auch (7)

Ppt lesson 10
Ppt lesson 10Ppt lesson 10
Ppt lesson 10
 
Ppt lesson 01
Ppt lesson 01Ppt lesson 01
Ppt lesson 01
 
Comando exit
Comando exitComando exit
Comando exit
 
Ppt lesson 11
Ppt lesson 11Ppt lesson 11
Ppt lesson 11
 
Comandos fecha-directorio-hora-version ms-dos
Comandos  fecha-directorio-hora-version ms-dosComandos  fecha-directorio-hora-version ms-dos
Comandos fecha-directorio-hora-version ms-dos
 
Ppt lesson 12
Ppt lesson 12Ppt lesson 12
Ppt lesson 12
 
Manual visual basic 6.0
Manual visual basic 6.0Manual visual basic 6.0
Manual visual basic 6.0
 

Ähnlich wie Ppt lesson 09

Lect02 Introducing Programming.ppt
Lect02 Introducing Programming.pptLect02 Introducing Programming.ppt
Lect02 Introducing Programming.pptNourhanTarek23
 
Chapter 05 show
Chapter 05 showChapter 05 show
Chapter 05 showchda01008
 
Chapter 08
Chapter 08Chapter 08
Chapter 08llmeade
 
Unit IV-Checkboxes and Radio Buttons in VB.Net in VB.NET
Unit IV-Checkboxes    and   Radio Buttons in VB.Net in VB.NET Unit IV-Checkboxes    and   Radio Buttons in VB.Net in VB.NET
Unit IV-Checkboxes and Radio Buttons in VB.Net in VB.NET Ujwala Junghare
 
Spf chapter 03 WinForm
Spf chapter 03 WinFormSpf chapter 03 WinForm
Spf chapter 03 WinFormHock Leng PUAH
 
Chapter2.ppt
Chapter2.pptChapter2.ppt
Chapter2.pptLalRatan
 
Csc153 chapter 03
Csc153 chapter 03Csc153 chapter 03
Csc153 chapter 03PCC
 
VB6_INTRODUCTION.ppt
VB6_INTRODUCTION.pptVB6_INTRODUCTION.ppt
VB6_INTRODUCTION.pptBhuvanaR13
 
C# Tutorial MSM_Murach chapter-10-slides
C# Tutorial MSM_Murach chapter-10-slidesC# Tutorial MSM_Murach chapter-10-slides
C# Tutorial MSM_Murach chapter-10-slidesSami Mut
 
LECTURE 12 WINDOWS FORMS PART 2.pptx
LECTURE 12 WINDOWS FORMS PART 2.pptxLECTURE 12 WINDOWS FORMS PART 2.pptx
LECTURE 12 WINDOWS FORMS PART 2.pptxAOmaAli
 
CIS/355 ilab 4 of 6
CIS/355 ilab 4 of 6CIS/355 ilab 4 of 6
CIS/355 ilab 4 of 6helpido6
 
Cis 355 ilab 4 of 6
Cis 355 ilab 4 of 6Cis 355 ilab 4 of 6
Cis 355 ilab 4 of 6ashhadiqbal
 
Practicalfileofvb workshop
Practicalfileofvb workshopPracticalfileofvb workshop
Practicalfileofvb workshopdhi her
 

Ähnlich wie Ppt lesson 09 (20)

Lect02 Introducing Programming.ppt
Lect02 Introducing Programming.pptLect02 Introducing Programming.ppt
Lect02 Introducing Programming.ppt
 
Chapter 05 show
Chapter 05 showChapter 05 show
Chapter 05 show
 
Chapter 08
Chapter 08Chapter 08
Chapter 08
 
Unit IV-Checkboxes and Radio Buttons in VB.Net in VB.NET
Unit IV-Checkboxes    and   Radio Buttons in VB.Net in VB.NET Unit IV-Checkboxes    and   Radio Buttons in VB.Net in VB.NET
Unit IV-Checkboxes and Radio Buttons in VB.Net in VB.NET
 
Spf chapter 03 WinForm
Spf chapter 03 WinFormSpf chapter 03 WinForm
Spf chapter 03 WinForm
 
Chapter2.ppt
Chapter2.pptChapter2.ppt
Chapter2.ppt
 
Csc153 chapter 03
Csc153 chapter 03Csc153 chapter 03
Csc153 chapter 03
 
VB6_INTRODUCTION.ppt
VB6_INTRODUCTION.pptVB6_INTRODUCTION.ppt
VB6_INTRODUCTION.ppt
 
C# Tutorial MSM_Murach chapter-10-slides
C# Tutorial MSM_Murach chapter-10-slidesC# Tutorial MSM_Murach chapter-10-slides
C# Tutorial MSM_Murach chapter-10-slides
 
Vb6.0 intro
Vb6.0 introVb6.0 intro
Vb6.0 intro
 
Intake 38 9
Intake 38 9Intake 38 9
Intake 38 9
 
LECTURE 12 WINDOWS FORMS PART 2.pptx
LECTURE 12 WINDOWS FORMS PART 2.pptxLECTURE 12 WINDOWS FORMS PART 2.pptx
LECTURE 12 WINDOWS FORMS PART 2.pptx
 
SPF WinForm Programs
SPF WinForm ProgramsSPF WinForm Programs
SPF WinForm Programs
 
Intake 37 9
Intake 37 9Intake 37 9
Intake 37 9
 
Chapter 3.2
Chapter 3.2Chapter 3.2
Chapter 3.2
 
CIS/355 ilab 4 of 6
CIS/355 ilab 4 of 6CIS/355 ilab 4 of 6
CIS/355 ilab 4 of 6
 
Cis 355 ilab 4 of 6
Cis 355 ilab 4 of 6Cis 355 ilab 4 of 6
Cis 355 ilab 4 of 6
 
Mca 504 dotnet_unit5
Mca 504 dotnet_unit5Mca 504 dotnet_unit5
Mca 504 dotnet_unit5
 
Visual studio.net
Visual studio.netVisual studio.net
Visual studio.net
 
Practicalfileofvb workshop
Practicalfileofvb workshopPracticalfileofvb workshop
Practicalfileofvb workshop
 

Mehr von Linda Bodrie

Mehr von Linda Bodrie (12)

Ppt lesson 08
Ppt lesson 08Ppt lesson 08
Ppt lesson 08
 
Ppt lesson 07
Ppt lesson 07Ppt lesson 07
Ppt lesson 07
 
Ppt lesson 06
Ppt lesson 06Ppt lesson 06
Ppt lesson 06
 
Ppt lesson 06
Ppt lesson 06Ppt lesson 06
Ppt lesson 06
 
Ppt lesson 06
Ppt lesson 06Ppt lesson 06
Ppt lesson 06
 
Ppt lesson 05
Ppt lesson 05Ppt lesson 05
Ppt lesson 05
 
Lesson 5 PP
Lesson 5 PPLesson 5 PP
Lesson 5 PP
 
Lesson 4 PowerPoint
Lesson 4 PowerPointLesson 4 PowerPoint
Lesson 4 PowerPoint
 
Ppt lesson 03
Ppt lesson 03Ppt lesson 03
Ppt lesson 03
 
Les 02 1
Les 02 1Les 02 1
Les 02 1
 
PowerPoint Lesson 2
PowerPoint Lesson 2PowerPoint Lesson 2
PowerPoint Lesson 2
 
PowerPoint Lesson 1
PowerPoint Lesson 1PowerPoint Lesson 1
PowerPoint Lesson 1
 

Kürzlich hochgeladen

Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxRustici Software
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Jeffrey Haguewood
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWERMadyBayot
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...apidays
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...apidays
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...Zilliz
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Zilliz
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 

Kürzlich hochgeladen (20)

Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 

Ppt lesson 09

  • 1. Microsoft Visual Basic 2005 BASICS Lesson 9 Nested If Statements and Radio Buttons
  • 2. Microsoft Visual Basic 2005 BASICS 2 Objectives  Use nested If statements.  Use radio buttons.  Use the Form Load event.  Use the Select Case statement.
  • 3. 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.
  • 4. Microsoft Visual Basic 2005 BASICS 4 Using Nested If Statements (cont.)
  • 5. Microsoft Visual Basic 2005 BASICS 5 Using Nested If Statements (cont.)
  • 6. 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.
  • 7. 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.
  • 8. Microsoft Visual Basic 2005 BASICS 8 Using Radio Buttons (cont.)
  • 9. 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
  • 10. Microsoft Visual Basic 2005 BASICS 10 Creating a GroupBox Control (cont.)
  • 11. Microsoft Visual Basic 2005 BASICS 11 Creating a GroupBox Control (cont.)
  • 12. Microsoft Visual Basic 2005 BASICS 12 Creating Radio Buttons in the GroupBox  Once the GroupBox is created  Add radio buttons to the GroupBox.
  • 13. 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
  • 14. Microsoft Visual Basic 2005 BASICS 14 Setting Radio Button Name and Text Properties (cont.)
  • 15. 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
  • 16. Microsoft Visual Basic 2005 BASICS 16 Adding Code to the Radio Buttons (cont.)
  • 17. Microsoft Visual Basic 2005 BASICS 17 Processing the Data  The final step  Calculate the result and create the output.
  • 18. 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.
  • 19. 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
  • 20. Microsoft Visual Basic 2005 BASICS 20 Using Select Case (cont.)  You can use conditional operators in a Case statement.
  • 21. 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.
  • 22. 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.
  • 23. 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.
  • 24. 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.
  • 25. 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.
  • 26. 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.