Consider the following If-Then-Else block. in Visual Studio .NET

Print QR Code 2d barcode in Visual Studio .NET Consider the following If-Then-Else block.

EXAMPLE 3.8
Recognizing Quick Response Code In Visual Studio .NET
Using Barcode Control SDK for Visual Studio .NET Control to generate, create, read, scan barcode image in VS .NET applications.
QR-Code Creator In .NET
Using Barcode encoder for .NET Control to generate, create QR-Code image in VS .NET applications.
Consider the following If-Then-Else block.
QR Code 2d Barcode Recognizer In .NET
Using Barcode scanner for VS .NET Control to read, scan read, scan image in .NET applications.
Creating Barcode In .NET Framework
Using Barcode generator for VS .NET Control to generate, create barcode image in .NET framework applications.
IF (status = "single") THEN tax = 0.2 * pay Else tax = 0.14 * pay END IF
Decoding Bar Code In Visual Studio .NET
Using Barcode scanner for VS .NET Control to read, scan read, scan image in Visual Studio .NET applications.
QR Creation In Visual C#
Using Barcode generation for VS .NET Control to generate, create Quick Response Code image in .NET applications.
If the logical expression status = "single" is true, then the first assignment statement will be executed. If the logical expression is false, however, the second assignment statement will be executed.
QR Code 2d Barcode Generation In Visual Studio .NET
Using Barcode creation for ASP.NET Control to generate, create Quick Response Code image in ASP.NET applications.
QR Code 2d Barcode Maker In VB.NET
Using Barcode generation for VS .NET Control to generate, create Quick Response Code image in Visual Studio .NET applications.
A more general form of the If-Then-Else block can be written as
Making Data Matrix In VS .NET
Using Barcode creator for VS .NET Control to generate, create DataMatrix image in VS .NET applications.
Making Matrix Barcode In .NET Framework
Using Barcode encoder for Visual Studio .NET Control to generate, create Matrix 2D Barcode image in .NET applications.
If logical expression 1 Then . . . . . . . .
Barcode Generation In .NET
Using Barcode creation for Visual Studio .NET Control to generate, create barcode image in VS .NET applications.
British Royal Mail 4-State Customer Code Generation In .NET
Using Barcode drawer for .NET framework Control to generate, create RM4SCC image in .NET applications.
executable statements
Make Barcode In .NET
Using Barcode printer for ASP.NET Control to generate, create barcode image in ASP.NET applications.
EAN-13 Scanner In Java
Using Barcode scanner for Java Control to read, scan read, scan image in Java applications.
. . . . . . . . ElseIf logical expression 2 Then . . . . . . . .
Data Matrix 2d Barcode Reader In C#.NET
Using Barcode reader for .NET framework Control to read, scan read, scan image in .NET framework applications.
Scanning Code 128 Code Set B In None
Using Barcode recognizer for Software Control to read, scan read, scan image in Software applications.
executable statements
GTIN - 12 Creation In VS .NET
Using Barcode creation for Reporting Service Control to generate, create UCC - 12 image in Reporting Service applications.
Recognizing ANSI/AIM Code 128 In Java
Using Barcode scanner for Java Control to read, scan read, scan image in Java applications.
. . . . . . . .
Code39 Generator In Visual Studio .NET
Using Barcode encoder for Reporting Service Control to generate, create Code 39 Extended image in Reporting Service applications.
Draw Barcode In .NET
Using Barcode creation for Reporting Service Control to generate, create bar code image in Reporting Service applications.
repeated ElseIf clauses
. . . . . . . . Else . . . . . . . .
executable statements
. . . . . . . . End If
In this form, If-Then clauses are embedded within prior Else clauses. Hence, we can construct conditional execution blocks that involve complex logical conditions.
EXAMPLE 3.9 ROOTS OF A QUADRATIC EQUATION
The roots of the quadratic equation ax2 + bx + c = 0 can be determined using the well-known formulas
BRANCHING AND LOOPING
[CHAP. 3
x1 =
b + b 2 4ac 2a b b 2 4ac 2a
x2 =
provided the quantity b2 4ac is positive. If b2 4ac is zero, we have a single (repeated) real root, determined as x = b / 2a If b2 4ac is negative, we have two complex roots. In this case, b + 4ac b 2 i 2a b 4ac b 2 i 2a
x1 =
x2 =
where i represents the imaginary number 1 In Visual Basic, we can accommodate these three situations with a group of If-Then-ElseIf-Else blocks, as shown below.
'Roots of a Quadratic Equation Dim a, b, c, d, x, x1, x2, real, imag d = (b ^ 2 4 * a * c) If d > 0 Then x1 = ( b + Sqr(d)) / (2 * a) x2 = ( b - Sqr(d)) / (2 * a) ElseIf d = 0 Then x = b / (2 * a) Else real = b / (2 * a) imag = Sqr( d) / (2 * a) End If 'real roots 'variant data types
'repeated root
'complex roots
We will see additional applications of If-Then and If-Then-Else blocks, in conjunction with other Visual Basic control structures, in the remaining sections of this chapter.
3.5 SELECTION: Select Case One way to select a block of statements from several competing blocks is to use a series of If-Then-Else or If-Then-ElseIf-Else blocks. This can be tedious, however, if the number of competing blocks is moderately large. The Select Case structure frequently offers a simpler approach to this type of situation. The most common form of the Select Case structure is written in general terms as
CHAP. 3]
BRANCHING AND LOOPING
Select Case expression Case value1
executable statements
Case value2
executable statements
. . . . . . . . Case Else
executable statements
End Select
The Case Else group is optional; it may omitted if one or more Case value groups are present. Similarly, the Case value groups may be omitted if the Case Else group is present. In practice, however, a Case Else group rarely appears alone, without any preceding Case value groups. When the Select Case structure is executed, the value of the expression is compared successively with value1, value2, etc., until a match is found. The group of executable statements following the matching Case statement is then executed, and control is passed to the first statement following End Select. If a match cannot be found among the available values (i.e., value1, value2, etc.), then the executable statements following Case Else are executed. The Select Case structure is particularly convenient when used in conjunction with a menu entry. In such situations the selection is based upon the menu item that is chosen.
EXAMPLE 3.10
Here is a Visual Basic program segment that makes use of a Select Case structure.
'Raise x to a Selected Power Dim x, z, n As Integer Select Case n Case 1 z = x Case 2 z = x ^ 2 Case 3 z = x ^ 3 'select a group of statements 'x ^ 1
'x ^ 2
'x ^ 3
Case Else 'error MsgBox("ERROR - Please try again") End Select
This program segment assumes that integer values have been assigned for x and n. The value of x, x ^ 2 or x ^ 3 is then assigned to z, depending on the value assigned to n. An error message will be displayed if n is assigned a value other than 1, 2 or 3. (See Sec. 4.13 for a discussion of the MsgBox function.)
The expression in the Select Case statement can be a string rather than a numeric expression. In this case, the values in the subsequent Case statements must also be strings. The original string expression will
Copyright © OnBarcode.com . All rights reserved.