Hi Everyone!
There are different ways of writing a same piece code which performs same task as the other. But one piece of code can make your and subsequent developers a cake walk while the other can make it really tough.
So not always the code which you write has the objective to just perform the function.
This blog is about Technology. One ultimate destination for tutorials on programming languages, exploring about complex situations in different programming languages. Also Knowing about most wanted technologies now and in Future. The Major content as of now will be focussed on Excel and Visual Basic for Applications(VBA). Have a happy reading...!!
Tuesday, January 5, 2010
Monday, January 4, 2010
Error Handler in VBA 7.0
Handling Error in form of programing language is vital task. To protect your application from stoping/freezing in midway is important. If you handle the error properly then you will not only successfully execute the application but you can also make user aware of the error which was thrown during the execution.
Lets us take a simple example for error handler:
Sub prTest()
'Error Handler Starts
On Error GoTo Err_PrTest:
Dim rngTest As Range
Dim intTest As Integer
Dim intCounter As Integer
If rngTest(1, 1) = 0 Then
'Do Nothing
End If
Exit_PrTest:
Set rngTest = Nothing
Exit Sub
Err_PrTest:
MsgBox Err.Description
GoTo Exit_PrTest
End Sub
Once this code goes into error below error is thrown to the user:
Lets us take a simple example for error handler:
Sub prTest()
'Error Handler Starts
On Error GoTo Err_PrTest:
Dim rngTest As Range
Dim intTest As Integer
Dim intCounter As Integer
If rngTest(1, 1) = 0 Then
'Do Nothing
End If
Exit_PrTest:
Set rngTest = Nothing
Exit Sub
Err_PrTest:
MsgBox Err.Description
GoTo Exit_PrTest
End Sub
Once this code goes into error below error is thrown to the user:
Subscribe to:
Posts (Atom)
Followers
Blog Archive
About Me
- Ravindra Singh Yadav
- Hello World!. I am an aspiring blogger, striving towards knowing more about various Technologies and innovating about it. I am full of Energy, Enthusiasm to learn more and more....