Error handling in vbscript, Visual Basic Programming

Assignment Help:

While a run-time error takes place, the properties of the Err object are filled with information which uniquely identifies the error & information which can be used to handle it. In order to generate a run-time error in your code, employ the VBScript Err Object Raise Method. The Err object's properties are reset at zero or zero-length strings ("") after an On Error Resume Next statement. The VBScript Err Object Clear technique can be utilized to explicitly reset Err object. The Err object is an intrinsic object along global scope - there is no requirement to generate an instance of it in your code.

Assume the following example that displays some of the possible errors which can be raised explicitly to generate run time errors.

<HTML>

<HEAD>

<TITLE>IGNOU</TITLE>

<SCRIPT LANGUAGE="VBScript">

<!--

Sub cmdSubmit_OnClick

On Error resume Next

'Check to make out if the user entered anything.

If (Len(document.form1.txtAge.value)  = 0)

Then MsgBox "before submitting you have to enter your age." Exit Sub

End If

'Check to make out if the user entered a number.

If (Not(IsNumeric(document.form1.txtAge.value ))) Then

MsgBox "You have to enter number for enter your age." Exit Sub

End If

'Check to make out if the age entered is valid.

If (document.form1.txtAge.value  <= 0) Or  (document.form1.txtAge.value  > 100)

Then

MsgBox "The age you entered is not applicable." Exit Sub

End If

' Data looks okay so submit it.

MsgBox "Thanks for entering age." document.form1.submit

End Sub

Sub cmdtype_OnClick

On Error Resume Next for i = 1 to 35

Err.clear

Err.Raise i

MsgBox Err.description & " - Error number - " &i

Next

End Sub

-->

</SCRIPT>

</HEAD>

<BODY  bgColor="#ffffcc" Text="#000099" >

<H1>Error Handling and validations</H1>

<B><P> This instance demonstrates validation techniques and Error handling in

VBScript. </P><?B>

<B>Please enter the age among 1 and 100. Or else, an error message would be flashed on clicking the submit button.</B>

<FORM NAME="form1">

<TABLE>

<TR>

<TD>Enter your age :</TD>

<TD><INPUT TYPE="Text" NAME="txtAge" SIZE="2"></TD>

</TR>

<TR>

<TD><INPUT TYPE="Button" NAME="cmdSubmit" VALUE="Submit"></TD>

<TD></TD>

<TD><INPUT TYPE="Button" NAME="cmdtype" VALUE="      Type Of Errors "></TD>

<TD></TD>

</TR>

</TABLE>

</FORM>

</BODY>

</HTML>

2485_Error Handling in VBScript.png

Figure: Error Handling in VBScript


Related Discussions:- Error handling in vbscript

Hierarchy of operation, what are the functions and the importance of hierar...

what are the functions and the importance of hierarchy operators

#title., Write a program to print a digital clock which displays the time f...

Write a program to print a digital clock which displays the time for 2 hours . ..

Graphics device interface - windows programming , Graphics Device Interface...

Graphics Device Interface - GDI:   The GDI is a windows API. The GDI uses a set of generic graphics objects to draw to the screen, to the memory and printers. Therefore the p

Vb script basics, This section will discuss the fundamentals of VBScript an...

This section will discuss the fundamentals of VBScript and define concepts such as datatypes, loops and others. VBScript Data Types VBScript contain only one data type called

Login form, How to create a login form in vb 2010

How to create a login form in vb 2010

MATHEMATICS PROJECT, HOW TO SOLVE ORDINARY DIFFERENTIAL EQUETION IN VISUAL ...

HOW TO SOLVE ORDINARY DIFFERENTIAL EQUETION IN VISUAL BASIC PROGRAMMING

Looping, how to make logic of o program and how to use loop

how to make logic of o program and how to use loop

Function procedures - vbscript, This is a series of VBScript statements enc...

This is a series of VBScript statements enclosed through the Function & End Function statements. A Function procedure is same to a Sub procedure, however can also return a value. T

If then else - control statement, If Then Else: The control statement ...

If Then Else: The control statement If Then Else is used for computing a condition and taking the action based on the condition. If the condition is true then the section will

Refresh method - data control, The Refresh Method: The refresh method ...

The Refresh Method: The refresh method transfer to the first record in the record set. To invoke the refresh method follow the syntax which is as shown below: Form1.Data1.R

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd