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

Assignment Statements

Notice that in addition to being used in If statements, the logical expression can also be a part of an assignment statement. That is, you can assign the result of a comparison (or logical operation, explained in the following section) to a numeric variable as follows:

D = A = B

In this statement, the first = represents the assignment operation (move the result of the operation on the right side to the variable on the left), and the second = is the equality comparison operator that compares whether A and B are equal. In this example, assuming D is a Boolean variable, it will have a value True if A is indeed equal to B; otherwise, it will have a value False. If D is of any kind of numeric data type other than Boolean, an implicit data type conversion will be required. The result will be –1 if A is equal to B; otherwise, it will be 0.
Of course, similar to any typical assignment statement, the result of a comparison can also be assigned to a property setting of any VB control that expects True or False. For example, suppose you would like to enable or disable a check box named chkDorm, depending on whether the variable, Score, is greater than or equal to 80. You can code the following:

chkDorm.Enabled = Score >= 80

This statement will enable the chkDorm check box when Score is greater than or equal to 80; otherwise, the check box will be disabled.

Last change: February 13 2016 18:47:58.
<<PreviousNext>>