Thursday, November 5, 2015

File Handling

11/5/2015

Handling Run time Errors:

Handle file I/O:


Resume:
The Resume statement is used to specify where to restart the flow of execution. This can either be a label or Next. If Next is used, the execution is continued from the statement following the statement that caused the error. An example of the Resume statement is displayed here. The 
ON ERROR Resume Next statement skips any run-time errors that may occur. The ON ERROR GoTo 0 statement turns off error trapping.

Err Object:
Visual Basic provides an inbuilt object called Err for handling errors. This object is used to retrieve information about the type of run-time error that has occurred. It can also be used to present information to the user if the user can solve the problem. The Err object has a set of properties and methods. These properties are reset to zero or zero-length strings (" ") after an Exit Sub, Exit Function, Exit Property, or Resume Next statement within an error-handling routine. You cannot reset the properties of the Err object by using any form of the Resume statement outside an error-handling routine. You can use the Clear method to reset the Err object explicitly.
    1. Number Property
          2. Description Property
      3. Source Property   
4. Clear Method
5. Raise Method 

Source Property -- It is a string expression of the location where the error has occurred in the application. If an unexpected run-time error occurs, Visual Basic sets the Err.Source property. If the error occurs in a standard topic, the source will be set to the project name. If the error occurs in a class topic, Visual Basic uses the project name and the class topic name.

Raise Method??? need more analysis
The Raise method of the Err object is used to generate errors within the code.

3 Types of file handling in VB:
1. Random Access
                                                                  2. Sequential Access(Works best with files containing only text)


Line Input# ----- the end-of-line character is not included when the line is read into the variables. 

Input# ------ The Input # statement is used to read the list of numbers or string expressions.

Write----- The Write statement writes data of any data type or format to an opened file.  You need to open a file for output, append, or random before you use the Write statement. It inserts a comma and quotes around strings automatically.

No comments:

Post a Comment