On Error GoTo 0 in Visual Studio .NET

Maker QR-Code in Visual Studio .NET On Error GoTo 0

On Error GoTo 0
Denso QR Bar Code Scanner In VS .NET
Using Barcode Control SDK for .NET framework Control to generate, create, read, scan barcode image in Visual Studio .NET applications.
QR Code Printer In .NET Framework
Using Barcode creator for .NET framework Control to generate, create Quick Response Code image in Visual Studio .NET applications.
This feature is useful if you want to activate error trapping in one part of a program, and then disable it in another part. Returning to the previous skeletal outline, now suppose that an error is not detected during program execution. The program logic will then continue sequentially, as usual, until the Exit Sub statement is encountered. The Exit Sub statement directs the program logic out of the event procedure, thus avoiding the error trap. Note that the Resume and Exit Sub statements are not always needed within an error handler. Or one may be required, but not the other. The program logic will dictate whether or not these statements will be included.
Decoding QR-Code In VS .NET
Using Barcode recognizer for .NET Control to read, scan read, scan image in .NET applications.
Barcode Generator In .NET Framework
Using Barcode creator for VS .NET Control to generate, create barcode image in .NET framework applications.
CHAP. 6]
Scan Barcode In Visual Studio .NET
Using Barcode decoder for .NET framework Control to read, scan read, scan image in Visual Studio .NET applications.
QR Code JIS X 0510 Creator In Visual C#
Using Barcode creator for Visual Studio .NET Control to generate, create QR Code JIS X 0510 image in VS .NET applications.
DEBUGGING AND EXECUTING A NEW PROJECT
QR Code Creation In Visual Studio .NET
Using Barcode creator for ASP.NET Control to generate, create QR Code JIS X 0510 image in ASP.NET applications.
QR Code ISO/IEC18004 Creator In VB.NET
Using Barcode creation for Visual Studio .NET Control to generate, create QR Code ISO/IEC18004 image in Visual Studio .NET applications.
Visual Basic associates an integer error code with each type of execution error. Thus, an error handler can process an error code (by means of an If-Then-Else block or a Select Case structure), and take appropriate corrective action. The complete list of error codes is extensive, including some that refer to error types that have not yet been discussed in this book. A representative list error codes that refer to some common execution errors is given in Table 6.1. Note the brief nature of the error messages.
Drawing Bar Code In .NET Framework
Using Barcode generation for .NET framework Control to generate, create barcode image in Visual Studio .NET applications.
GS1 128 Creation In .NET
Using Barcode printer for Visual Studio .NET Control to generate, create EAN128 image in .NET framework applications.
Table 6.1 Some Representative Error Codes Error Code 3 5 6 7 9 11 13 14 16 17 18 20 35 51 57 61 68 70 91 92 93 94 Corresponding Error Message
Generate Code 128 Code Set C In Visual Studio .NET
Using Barcode maker for VS .NET Control to generate, create Code 128 image in .NET applications.
EAN-8 Generator In .NET Framework
Using Barcode maker for VS .NET Control to generate, create EAN8 image in .NET framework applications.
Return without GoSub
Data Matrix ECC200 Creator In C#.NET
Using Barcode encoder for .NET framework Control to generate, create Data Matrix ECC200 image in VS .NET applications.
Data Matrix Maker In Java
Using Barcode creation for Android Control to generate, create Data Matrix 2d barcode image in Android applications.
Invalid procedure call or argument Overflow Out of memory Subscript out of range Division by zero Type mismatch Out of string space Expression too complex Can't perform requested operation User interrupt occurred Resume without error Sub, Function or Property not defined Internal error Device I/O error Disk full Device unavailable Permission denied Object variable or With block variable not set For loop not initialized Invalid pattern string Invalid use of Null
Decode UCC.EAN - 128 In VB.NET
Using Barcode reader for VS .NET Control to read, scan read, scan image in .NET applications.
Encode USS Code 39 In Java
Using Barcode generation for Android Control to generate, create USS Code 39 image in Android applications.
EXAMPLE 6.3 AN ERROR HANDLER
GS1 - 13 Creation In Java
Using Barcode drawer for Java Control to generate, create GTIN - 13 image in Java applications.
Data Matrix Reader In None
Using Barcode recognizer for Software Control to read, scan read, scan image in Software applications.
A student has written a Visual Basic program to determine the real roots of the quadratic equation ax2 + bx + c = 0 using the well-known formulas b + b 2 4ac , 2a b b 2 4ac 2a
Printing UPC-A Supplement 2 In Objective-C
Using Barcode printer for iPhone Control to generate, create GS1 - 12 image in iPhone applications.
Drawing DataMatrix In None
Using Barcode creation for Office Excel Control to generate, create Data Matrix image in Excel applications.
x1 =
x2 =
These formulas are valid only when a > 0 (to avoid division by zero) and b2 > 4ac (to avoid attempting to take the square root of a negative number). The Form Design Window is shown in Fig. 6.21.
DEBUGGING AND EXECUTING A NEW PROJECT
[CHAP. 6
Fig. 6.21
Fig. 6.22 shows the corresponding Visual Basic code in the Code Editor Window. Note that the code does not include any provisions to test for improper input conditions; i.e., a = 0, or b2 4ac.
Fig. 6.22
CHAP. 6]
DEBUGGING AND EXECUTING A NEW PROJECT
When this program is executed with a dataset that satisfies the required conditions, such as a = 2, b = 5 and c = 3, it displays the correct calculated values x1 = 1 and x2 = 1.5, as shown in Fig. 6.23. However, if the program is executed with a dataset that violates the condition b2 > 4ac, such as a = 5, b = 2, c = 3, an error message is generated, as shown in Fig. 6.24, and the program stops. The user may then either terminate the computation or enter the debugger.
Fig. 6.23
Fig. 6.24
Similarly, if the program is executed with a = 0, b = 2, and c = 3, we obtain the error message shown in Fig. 6.25.
Fig. 6.25
DEBUGGING AND EXECUTING A NEW PROJECT
[CHAP. 6
To remedy these conditions, the student has added an error handler to event procedure Command1_Click() that tests for each of the two error conditions. When activated, the error handler displays a more descriptive error message and clears the input data fields, thus allowing the user to enter another dataset without first shutting down the program. The corrected Visual Basic code is shown below.
Private Sub Command1_Click() Dim a, b, c, d, x1, x2 On Error GoTo ErrorMessage a = Val(Text1.Text) b = Val(Text2.Text) c = Val(Text3.Text) d = (b ^ 2 - 4 * a * c) 'calculate discriminant
x1 = (-b + Sqr(d)) / (2 * a) x2 = (-b - Sqr(d)) / (2 * a) Text4.Text = Str(x1) Text5.Text = Str(x2) Exit Sub ErrorMessage: If Err.Number = 5 Then MsgBox ("Negative discriminant (b^2 < 4ac): Re-enter input data") ElseIf (Err.Number = 6 Or Err.Number = 11)Then MsgBox ("Division by zero (a = 0): Re-enter input data") End If Resume ClearInput ClearInput: Text1.Text = "" Text2.Text = "" Text3.Text = "" End Sub Private Sub Command2_Click() Text1.Text = "" Text2.Text = "" Text3.Text = "" Text4.Text = "" Text5.Text = "" End Sub Private Sub Command3_Click() End End Sub
If an error is encountered during program execution, the OnError GoTo ErrorMessage statement directs the program logic to the error handler, whose first statement is identified by the label ErrorMessage: (Note that the colon is a part of
CHAP. 6]
Copyright © OnBarcode.com . All rights reserved.