select case for error

please give me a code that each time there a error it will go directly to select cased statement, its mean that i dont need to declare 1 by 1 the error for each job.
JOHNHOAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

hessCommented:
on error goto error handeler


(code)
(code)
(code)

exit sub
errorhandeler:
(select case.....)

is that what you need?
0
hessCommented:
on error goto errorhandeler
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
tureCommented:
JOHNHO,

Create a form with only one commandbutton, enter this code:

Private Sub Command1_Click()
  Dim x As Byte
 
  'All errors will branch to errhandler
  On Error GoTo errhandler
 
  'Enter a value for x
  x = InputBox("Enter a value for x:")
 
  'If x is 10 - 19 cause an overflow error
  If x >= 10 And x < 20 Then x = x * 1000
 
  'If x is 20 - 29, cause a division by 0 error
  If x >= 20 And x < 30 Then x = x / 0
 
  'If x >= 30, cause a file not found error
  If x >= 30 Then
    Open "c:\test\nonexist.txt" For Input As 1
    Close 1
  End If
 
  'Turn off error handling.
  On Error GoTo 0
 
  'Get out of this procedure before reaching the error handler
  Exit Sub
 
errhandler:
 
  'Display the error number and error description
  MsgBox Err.Number & ": " & Err.Description
 
  'Perform different tasks depending on the error
  Select Case Err.Number
    Case 11 'Division by 0
      x = 0
      'Continue execution after the statement that caused the error
      Resume Next
   
    Case 53 ' File not found
      MsgBox "You need to create the file first."
      'Continue execution after the statement that caused the error
      Resume Next
     
    Case Else
      MsgBox "Unknown error. Cancelling operation abruptly."
      End
     
  End Select
End Sub

Ture Magnusson
Karlstad, Sweden
0
Éric MoreauSenior .Net ConsultantCommented:
Do you want that any error that occurs in any subs go to one error handler without placing error handling in any of these subs? If this is what you want (what we called a general on error goto ...), THIS CANNOT BE DONE IN VB!

You have to write code in each sub in which you want error trapping!
0
FeresCommented:
if i understood well, and emoareau is saying what you need to know, then there is a way.
create a module and place a sub named Main then go to project properties and set start up object for sub Main so:

on error goto errorHandle
frmMain.Show
exit sub
errorHandle:
'Place select case here
select case err.Number
  case 123
  case 321
  .
  .
  .
end select

if you want to disable the handle error and let vb raise an error set

on error goto 0

but if you want to handle a particular error in a sub

on local error goto errorHandle

exit sub
errorHandle:

end sub

Well, that's the idea.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.