Visual Basic 2008 Programming: Business Applications with a Design Perspective
Chapter 1 Chapter 2 Chapter 3 Chapter 4 Chapter 5 Chapter 6 Chapter 7 Chapter 8 Chapter 9
Chapter 10 Chapter 11 Chapter 12 Chapter 13 Chapter 14 Appendix A Appendix B Appendix C Home
Last change: February 13 2016 18:48:19.

 Chapter in PDF

Table of Contents

Chapter 5: Decision
Last change: February 13 2016 18:47:58.

Chapter 5

Beginning with Chapter 2, “Introduction to Visual Basic Programming,” you have seen the need for the If statement (or block) to make a program work properly. It is not an exaggeration to claim that you just cannot write a program without the use of the If block. This is true because however simple a programming problem may be, it is bound to involve some decisions; that is, depending on the condition of one thing, something else will have to be handled differently. For example, suppose your program has a check box, which is used to ascertain whether a patient of a clinic is insured. If so, you want to enable a group box for the user to enter insurance information; otherwise, the group box will be disabled. You will need to use the If block in the check box’s CheckedChanged event to determine whether the check box is checked or unchecked, and to execute the proper code accordingly.
When you used the If block previously, you basically looked at the syntax. It is now time to take a closer look at its structure and additional details. Sometimes, various alternative actions need to be taken depending on the result obtained from a single expression, a situation commonly referred to as branching. In such a case, coding with the If block structure can become cumbersome. VB provides an alternative structure, the Select Case block, to handle this situation more concisely. This structure is examined in this chapter.
Both the If block and the Select Case block structures involve the use of logical expressions, which are expressions that can be evaluated to a Boolean value, True or False. For you to thoroughly understand both structures, it is best to have a basic understanding of logical expressions first.
After you finish this chapter, you should be able to:

Last change: February 13 2016 18:47:57.