VB6 beginners tutorial - Learn VB6

Advanced VB6 tutorial - Learn Advanced VB6

Systems Analysis - System analysis and Design tutorial for Software Engineering

Browse Topics

- Getting started
- Data Types
- Modules
- Operators in VB6
- VB6 Variable
- VB6 Procedures
- VB6 Control Structures
- Loops in VB6
- VB6 Exit Do & With End With
- Arrays in VB6
- User-Defined Data Types
- VB6 Constants
VB6 Built-in Functions
- Date and Time in VB6
- VB6 Controls
- TextBox Control
- ComboBox & OptionButton
- Label & Frame
- PictureBox & ImageBox
- Timer Control
- ListBox & ComboBox
- VB6 ScrollBar
- Control Arrays in VB6
- Files controls in VB6
- VB6 CheckBox
- Forms in VB6
- Menus in VB6
- MDI Form in VB6
- InputBox
- MessageBox
- Mouse events
- Mouse Move
- Error Handling
Error Handling (2)
VB6 Database

You are here: Visual Basic > VB6 (Beginners Tutorial)

Tutorial Main Page | Previous Page | Contents | Next Page

Error-Handling, Debugging - Example - Simple Error Trapping

1. Start a new project. Add a text box and a command button.

2. Set the properties of the form and each control:

BorderStyle - 1-Fixed Single
Caption - Error Generator
Name frmError

Caption - Generate Error
Default - True
Name - cmdGenError

Name - txtError
Text - [Blank]

The form should look something like this:

3. Attach this code to the cmdGenError_Click event.

Private Sub cmdGenError_Click()
On Error GoTo HandleErrors
Err.Raise Val(txtError.Text)
Exit Sub

Select Case MsgBox(Error(Err.Number), vbCritical + vbAbortRetryIgnore, "Error Number" + Str(Err.Number))

Case vbAbort
  Resume ExitLine
Case vbRetry
Case vbIgnore
  Resume Next
End Select


Exit Sub
End Sub

In this code, we simply generate an error using the number input in the text box. The generic error handler then displays a message box which you can respond to in one of three ways.

4. Save your application. Try it out using some of these typical error numbers (or use numbers found with on-line help). Notice how program control changes depending on which button is clicked.

Error Number    Error Description

6                       Overflow
9                       Subscript out of range
11                     Division by zero
13                     Type mismatch
16                     Expression too complex
20                     Resume without error
52                     Bad file name or number
53                     File not found
55                     File already open
61                     Disk full
70                     Permission denied
92                     For loop not initialized


Tutorial Main Page | Previous Page | Contents | Next Page


Home | About Us | Privacy Policy | Contact Us

Copyright © | All Rights Reserved