Jump to content




Recent Status Updates

  • Photo
      18 Aug
    KodeKool

    When faced with a wall of errors and no hope to fix them, remember the following "Programs always do what you tell them to, and seldom what you want them to, but eventually you'll run out of things that can go wrong and it'll just work. and that's the secret to good programming."

    Show comments (2)
  • Photo
      11 Aug
    Error

    Should I be practicing programming every day? I feel if I don't, I'll get instantly rusty or something.

    Show comments (4)
View All Updates

Developed by Kemal Taskin
Photo
- - - - -

VB6.0:Tutorial, Error handling

Visual Basic 4 / 5 / 6 form

  • Please log in to reply
11 replies to this topic

#1 TcM

TcM

    CC Mentor

  • VIP Member
  • PipPipPipPipPipPipPipPip
  • 7,563 posts

Posted 15 October 2006 - 01:36 AM

Introduction:-
Ok So I decided to make a tutorial about error handling! Many programs don't contain error handling but I suggest you that you include it! This will make your program more powerful

Solution:-
Ok so I am going to show you this code then I will expalin it. I will show you 3 types of error handling

What you need:-
3 Command buttonsSome time
Here is the code
Private Sub Command1_Click()
On Error GoTo ErrorHandler
Error 424 'This error is displayed when there is a missing object
Exit Sub
ErrorHandler:
MsgBox "Error Number: " & Err.Number & " With The Description ->> " & Err.Description & " <<- Occured."
End Sub

Private Sub Command2_Click()
On Error GoTo ErrorHandler
Error 424
Exit Sub
ErrorHandler:
If Err.Number = 424 Then
MsgBox "A missing object in your form is needed!, Please refer to the code and arrange accordingly!"
Else: MsgBox "Error Number: " & Err.Number & " With The Description ->> " & Err.Description & " <<- Occured."
End If
End Sub

Private Sub Command3_Click()
On Error Resume Next
Error 424 'This error is displayed when there is a missing object
MsgBox "error ignored!"
End Sub


Explanation:-
On Error GoTo ErrorHandler

This will tell the program that when an error is found it will call the 'chunk' of code named ErrorHandler ( you will see it in a while )

Error 424 'This error is displayed when there is a missing object
Exit Sub

This will generate an error, instead of this code you will have your code here, I just made that for an error to be generated so DON'T include that in your program this is just for testing purposes!!! and the 2nd line is there so to IF no error occurs the 'chunk' of code named ErrorHandler will not be executed

Posted Image

ErrorHandler:
MsgBox "Error Number: " & Err.Number & " With The Description ->> " & Err.Description & " <<- Occured."
End Sub
[code]
This will be the action that will be done when an error occurs it will show you the error number and the description!

[code]
ErrorHandler:
If Err.Number = 424 Then
MsgBox "A missing object in your form is needed!, Please refer to the code and arrange accordingly!"
Else: MsgBox "Error Number: " & Err.Number & " With The Description ->> " & Err.Description & " <<- Occured."
End If
[/code]
This will be found on the Command2 event instead this type of error handling is when the programmer knows for example that when something is done the error will popup so he should make this type of error handling so not to let his program crash. here I edded IF .... THEN.... ELSE so IF the error number is 424 THEN it will do something or if not ELSE it will show the first method

[IMG]http://forum.codecall.net/images/Tutorials/2ns6.jpg[/IMG]

[code]
On Error Resume Next
Error 424 'This error is displayed when there is a missing object
MsgBox "error ignored!"

Posted Image

Here we are telling the program to just IGNORE the error and continue the next action ( in this case show a msg box )

Conclusion:-
As Always Feedback is welcome and the full source is attached!!

Attached Files


  • 0

#2 TcM

TcM

    CC Mentor

  • VIP Member
  • PipPipPipPipPipPipPipPip
  • 7,563 posts

Posted 26 November 2006 - 04:41 AM

OMG pls Jordan can you remove this spammers post thanks!
  • 0

#3 Guest_Jordan_*

Guest_Jordan_*
  • Guest

Posted 26 November 2006 - 08:33 AM

Wow, that is the 4th one I have removed from this tutorial. They really like this one!
  • 0

#4 TcM

TcM

    CC Mentor

  • VIP Member
  • PipPipPipPipPipPipPipPip
  • 7,563 posts

Posted 26 November 2006 - 09:57 AM

Lol! its my tutorial :) of course they like it!! lol just kidding! duh damm spammers! they are all over the net!!
  • 0

#5 xXHalfSliceXx

xXHalfSliceXx

    CC Leader

  • Retired Mod
  • PipPipPipPipPipPipPip
  • 1,560 posts

Posted 26 November 2006 - 10:03 AM

Suggested that we enable Image Verification on registration. I made a thread about it for the Mods/Admins to comment.
  • 0

Posted Image
Posted Image


#6 TcM

TcM

    CC Mentor

  • VIP Member
  • PipPipPipPipPipPipPipPip
  • 7,563 posts

Posted 26 November 2006 - 10:23 AM

Suggested that we enable Image Verification on registration. I made a thread about it for the Mods/Admins to comment.


Well I sugegsted another thing in here:-
http://forum.codecal...f.html#post8774
This would definitely make it harder!!
  • 0

#7 TcM

TcM

    CC Mentor

  • VIP Member
  • PipPipPipPipPipPipPipPip
  • 7,563 posts

Posted 26 November 2006 - 10:25 AM

Wow, that is the 4th one I have removed from this tutorial. They really like this one!


Well perhaps because it has 4 votes? as rating? I really dont know!!
  • 0

#8 mathewbuer.com

mathewbuer.com

    CC Lurker

  • Just Joined
  • Pip
  • 1 posts

Posted 20 January 2008 - 01:13 AM

i am hqavin a javascript error will this resolve this issue?
  • 0

#9 utardylan

utardylan

    CC Lurker

  • Just Joined
  • Pip
  • 1 posts

Posted 04 May 2008 - 06:34 PM

i will take a look
  • 0

#10 TcM

TcM

    CC Mentor

  • VIP Member
  • PipPipPipPipPipPipPipPip
  • 7,563 posts

Posted 06 June 2008 - 10:31 AM

i am hqavin a javascript error will this resolve this issue?


This is a VB tutorial not a JS one.
  • 0

#11 AcroneShadow

AcroneShadow

    CC Newcomer

  • Just Joined
  • PipPip
  • 14 posts

Posted 11 December 2008 - 05:25 PM

Ahh very nice. This will definately make things so much better for my progs. Best of luck :cool:
  • 0

#12 chaoz

chaoz

    CC Lurker

  • Just Joined
  • Pip
  • 1 posts

Posted 22 December 2008 - 08:03 PM

thanks bro never used error handling in my progs before now i can make them run smoother
  • 0





Also tagged with one or more of these keywords: Visual Basic 4 / 5 / 6, form