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

Files in a sdi and mdi application, Files in a SDI and MDI Application: ...

Files in a SDI and MDI Application: Both the SDI and MDI projects have 4 implementation files (.cpp extension). These are the files equivalent to the Document Class, View Clas

Program to draw a rectangle shape , Create a project that draw a rectangle ...

Create a project that draw a rectangle shape which may be either (*) or (+) according to the selected radio button. The number of rows in the shape will be taken from the 1 st

Attributes, departmental store attributes

departmental store attributes

Simple programming, For this assignment you have to design and implement a ...

For this assignment you have to design and implement a VB.NET project which prepares a bill of payment due, given the purchase amount. The project models a typical purchase transac

Project on VB6.0, I need a VB6 software for making a soccerboard for 10 tea...

I need a VB6 software for making a soccerboard for 10 teams & automatically generate their fixtures

Software that is rude - basics of gui design, Software That Is Rude: T...

Software That Is Rude: The software warns the user for making the mistakes. The Message boxes pop up representing the mistake and the user will have to click the OK or CANCEL

John Galt requests a program to double-check his Gas Bill, John''s gas supp...

John''s gas supply is read from a 4-digit meter each month that shows the current total gas used in cubic meters. The amount of gas used that month is determined by subtracting t

Vbscript dictionary object properties, Just like normal objects Dictionary ...

Just like normal objects Dictionary object also has definite properties. These properties can be set to any valid value & can be retrieved as and while required. Pr

Document interfaces - visual basic programming, DOCUMENT INTERFACES   ...

DOCUMENT INTERFACES   A SDI (Single document interface) and the MDI (Multiple document interfaces) are the document interfaces. The MDI based applications can have numerous ch

Program for computing automobile repair bills, A program is needed to assis...

A program is needed to assist computing automobile repair bills. The cost of labor is $35 per hour. The costs for parts are subject to a 5% sales tax, which should be added t

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