2: Controlling Your Programs in VS .NET
2: Controlling Your Programs Generate Barcode In .NET Using Barcode generation for ASP.NET Control to generate, create bar code image in ASP.NET applications. In This
UPCA Printer In C# Using Barcode printer for VS .NET Control to generate, create GTIN - 12 image in Visual Studio .NET applications. Setting conditions with the If statement Zeroing in on the Select Case statement Reaching a particular value with the For statement Setting a time limit with the While statement Specifying tasks with the Do statement Creating Universal Product Code Version A In VS .NET Using Barcode creation for Visual Studio .NET Control to generate, create UPC Code image in .NET framework applications. nly the most trivial of programs execute their tasks one at a time, in the exact sequence in which the statements are listed in the program Life, even in the world of programming, just isn t that simple Most programs require more control over the sequence in which statements are executed For example, you may need to skip over some statements based on the results of a condition test Or, you may need to create a loop of statements that repeats itself a given number of times or until a certain condition is met This chapter describes the VBNET statements that let you control the flow of execution for your ASPNET programs Encoding UPCA In Visual Basic .NET Using Barcode encoder for Visual Studio .NET Control to generate, create UPC A image in .NET framework applications. Using If Statements
Bar Code Generation In .NET Using Barcode creator for ASP.NET Control to generate, create barcode image in ASP.NET applications. The Robert Frost poem that begins, Two roads diverged in a yellow wood is an apt description of how the If statement works The program is rolling along, executing one statement after another, until it comes to an If statement The If statement represents a fork in the road; a choice must be made about which path to take Many programs have to make such either/or decisions as they execute For example, a program that writes data entered by the user into a database has to make a determination first: Did the user actually enter some data If so, the program writes the data to the database If not, the program displays an error message saying something along the lines of, Yo! You didn t enter anything! To process this decision, the program uses an If statement Barcode Generation In .NET Framework Using Barcode maker for ASP.NET Control to generate, create bar code image in ASP.NET applications. Using If Statements
Encoding Bar Code In VB.NET Using Barcode printer for Visual Studio .NET Control to generate, create barcode image in VS .NET applications. VB s If statement is remarkably flexible, with several formats to choose from All these forms involve three basic parts: A condition test, in which a conditional expression is evaluated to yield a value of True or False (There s more about conditional expressions later in this chapter) A Then part, which supplies one or more statements that execute only if the result of the condition test is True An Else part, which supplies one or more statements that execute only if the result of the condition test is False For example, consider these lines: Data Matrix 2d Barcode Drawer In VS .NET Using Barcode encoder for Visual Studio .NET Control to generate, create Data Matrix 2d barcode image in .NET applications. If txtLastNameText <> Then Add the last name to the database Else Display an error message End If ANSI/AIM Code 39 Generation In C# Using Barcode drawer for .NET Control to generate, create ANSI/AIM Code 39 image in Visual Studio .NET applications. Here the If statement begins with a condition test that checks to see whether the user entered anything in the txtLastName text box If so, that data is written to the database; if not, an error message is displayed The If statement takes various useful forms, with varying degrees of complexity The following sections dig deeper into the basics of using them Recognizing GTIN - 12 In Visual Studio .NET Using Barcode reader for VS .NET Control to read, scan read, scan image in .NET framework applications. The basic If statement
Barcode Drawer In Visual Basic .NET Using Barcode printer for Visual Studio .NET Control to generate, create barcode image in VS .NET applications. The most basic form of the If statement looks like this: Paint Code39 In .NET Using Barcode maker for Visual Studio .NET Control to generate, create Code 3/9 image in .NET framework applications. If expression Then statements executed if true End If
Code 3/9 Generator In Java Using Barcode creator for Java Control to generate, create Code 39 Full ASCII image in Java applications. Each component of the If statement must fall on a separate line, as shown in the preceding structure In other words, you shouldn t place the statements on the same line as the Then or Else keywords Here s an example of a typical If statement: Code 128 Code Set C Encoder In VS .NET Using Barcode creation for VS .NET Control to generate, create Code 128 Code Set B image in .NET framework applications. Dim CommissionRate As Decimal If SalesTotal > 10000D Then CommissionRate = 005D End If
Barcode Decoder In Java Using Barcode reader for Java Control to read, scan read, scan image in Java applications. In this example, a variable named CommissionRate is set to 005 if Sales Total is greater than $10,000 Drawing Bar Code In VS .NET Using Barcode maker for .NET Control to generate, create bar code image in Visual Studio .NET applications. Using If Statements
Encoding EAN13 In Java Using Barcode maker for Java Control to generate, create EAN13 image in Java applications. Book V 2
Recognize EAN 13 In .NET Framework Using Barcode scanner for Visual Studio .NET Control to read, scan read, scan image in VS .NET applications. Here s an example that executes more than one statement if the condition test is True: Scanning ECC200 In .NET Framework Using Barcode scanner for VS .NET Control to read, scan read, scan image in Visual Studio .NET applications. Dim CommissionRate As Decimal If SalesTotal > 10000D Then CommissionRate = 005D Commission = SalesTotal * CommissionRate End If Generate GTIN - 128 In Java Using Barcode drawer for Java Control to generate, create GTIN - 128 image in Java applications. Controlling Your Programs
The single-line If
VBNET also allows you to use a single-line form of the If statement, which looks like this: If condition Then statement [Else statement] To use this form of the If statement, the condition, Then clause, and Else clause (if any) must all be coded on the same line Here s an example: If x > 0 Then ResponseWrite( X is & x) The preceding example displays the message X is n, where n is the value of x But the message appears only if x is greater than zero You can include more than one statement in the Then part by separating the statements with colons But if more than one statement is required, or if an Else part is required, I suggest you use the basic multiline If form instead of the single-line form
|
|
|
|
| ALL RIGHTS RESERVED. Business Refinery (c) 2006 - 2010. | Terms of Use | Privacy Policy |