Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 166
  • Last Modified:

Error in VB

How can I determine name of a module and a sub or a function where an error occurred?

thanks
kloppa
0
kloppa
Asked:
kloppa
  • 7
  • 4
  • 4
  • +9
1 Solution
 
gencrossCommented:
The err.source will give you limited information.

You can also create an error routine passing it the information you are looking for from the err handler in the sub routine.  This requires an error handler in each routine calling this function...

Function ErrHandler(Number as double,Source as string, otherinfo as string)

msgbox "Error occured in " & Source & " - " & Number

end function

You can then have the function return data if you need it.

Hope this helps
0
 
Anthony PerkinsCommented:
Use Error Handling and add the name of the module and procedure in your Error Handling code.

Anthony
0
 
bruintjeCommented:
Hi, Kloppa

the dirty way is use a global error string like

public strErrorMessage as string

sub main()
  on error goto errhandle
    'do your processing
  exit sub
  errhandle:
    debug.print " Error occured in " & strErrorMessage & " vb error number :" & err.number & " vb error message " & err.description
  exit sub
end sub

and use in your program something hardcoded like strErrorMessage = " module X procedure Z " 

this is the dirty way

a cleaner way is first reading up on hte subject

http://www.vb-helper.com/tut6.htm

then look at a tool like

http://www.gridlinx.com/errorhdl.htm

HTH:O)Bruintje
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
kloppaAuthor Commented:
thanks for your responses.

but i am looking for the ways to get that data without having to write it manualy.

thanks,
kloppa
0
 
Éric MoreauSenior .Net ConsultantCommented:
>>but i am looking for the ways to get that data without having to write it manualy.

This can't be done.
0
 
Anthony PerkinsCommented:
>>but i am looking for the ways to get that data without having to write it manualy.<<

Sometimes as developers we have to write code.

Anthony
0
 
kloppaAuthor Commented:
I am just trying to be a good boy and to avoid hardcoding :)

kloppa
0
 
gencrossCommented:
In each routine you should have an errorhandler (good coding practice).  There would not be anything wrong with hardcoding the name of the routine and/or module in the errorhandler.  You can then pass this info to a standard error routine or do whatever you like with it.
0
 
kloppaAuthor Commented:
how can i split the points between you all? :)

kloppa
0
 
rpaiCommented:
Take a look at this, might be of some help.

Private Function MyTest()
Dim x As Integer
Dim y As Integer

On Error GoTo errhandler
    y = x / 0
   
    Exit Function

errhandler:
    HandleError "MyTest"
End Function

Function HandleError(strFunctionName As String)
    App.LogEvent vbCrLf & "Error in Function ::" & strFunctionName, vbLogEventTypeError
End Function

NOTE: You have to compile this to see the message in the Event Viewer.
0
 
pjbaratelliCommented:
If you do not want to hard code the actual error handling, write a class that handles all your errors.  Then make the class global so you can make one change to error handling class for all your error handling.

You still need to write a hook into each sub though.
0
 
carpediemCommented:
If you don't mind purchasing something, this is a pretty cool tool that will do the work for you.

http://hallogram.com/devvb/failsafe/
0
 
carpediemCommented:
Here is a link to the actual product homepage
http://www.compuware.com/products/devpartner/visualbasic/failsafevb.htm
0
 
Richie_SimonettiIT OperationsCommented:
acperkins wrotes:
"Sometimes as developers we have to write code.

Anthony"
you're kidding, aren't you?
0
 
Anthony PerkinsCommented:
Richie,

Muy chistoso! (Translation: Very funny!)

Anthony
0
 
Arthur_WoodCommented:
actually Richie, he is not kidding...Far too many users of VB think that it just happens by osmosis - or dumb-luck.  That is why the belly-aching is so loud about VB.NET, which will weed out all of the cry-babies, who never want to have to write REAL code.

Arthur
0
 
Anthony PerkinsCommented:
Arthur,

Trust me, Richie was kidding.  But your point is well made.  Unfortunately, VB has got a bad rap over the years, because way too many so called developers started programming because it was so simple to use, without realizing that there is far more to programming than designing forms.  And as you say, hopefully .NET will change this.

Anthony
0
 
Richie_SimonettiIT OperationsCommented:
Osmosis... i like it, where i can buy some of it? I hate pills, so... it comes in a way that i could drink it?

(just kidding)
0
 
kloppaAuthor Commented:
Thanks everyone for the replies.
Unfortunately I didn’t get a satisfactory answer and have to delete the question.

kloppa

0
 
Anthony PerkinsCommented:
So you did you not get the answer you wanted to hear and that is why you are deleting it, is that what you are saying?

Anthony
0
 
bruintjeCommented:
Kloppa > in this case i don't mind shower some points to two of the other particpants and everyone is happy :)

Anthony > everyone said the same and it's a bit difficult to split it into 8 for such a basic question isn't it?
0
 
Anthony PerkinsCommented:
bruintje,

If I thought the problem was dividing 100 by 8 I would agree with you and quite frankly I don't care about the points.  Unfortunately, I believe the answer was not as palatable as the questioner would have liked and this I find objectionable.

Anthony
0
 
bruintjeCommented:
Anthony, you're right.......

but if questions degrade into the asker not being happy and then cancelling the complete thread (especially since he already said how can i pass them to you all) i'll leave it there

much better for my health, and in the game it's

win some lose some

Take care,
Brian
0
 
Éric MoreauSenior .Net ConsultantCommented:
>>i'll leave it there

You should at least ask the community support to refund points and move to the PAQ.
0
 
Anthony PerkinsCommented:
Eric,

>>You should at least ask the community support to refund points and move to the PAQ. <<
I agree, but unfortunately in view of the questioner's attitude, I suspect the chances of that happening are nil.

Anthony
0
 
Éric MoreauSenior .Net ConsultantCommented:
>>I agree, but unfortunately in view of the questioner's attitude, I suspect the chances of that happening are nil.

Maybe you should recommend CS yourself on the issue of this question if you have any doubt about the asker.
0
 
DanRollinsCommented:
Hi kloppa,
It appears that you have forgotten this question. I will ask Community Support to close it unless you finalize it within 7 days. I will ask a Community Support Moderator to:

    Split points between: gencross and acperkins@devx and bruintje

kloppa, if you think your question was not answered at all or if you need help, just post a new comment here; Community Support will help you.  DO NOT accept this comment as an answer.

EXPERTS: If you disagree with that recommendation, please post an explanatory comment.
==========
DanRollins -- EE database cleanup volunteer
0
 
Éric MoreauSenior .Net ConsultantCommented:
as of 05/20/2002 02:46PM PST

Thanks everyone for the replies.
Unfortunately I didn’t get a satisfactory answer and have to delete the question.

kloppa



Me opinion is that the question should be deleted or refund/send to PAQ.
0
 
DanRollinsCommented:
Thanks for the input emoreau.
I made my recommendation because I believe that this is one of those questions where "it can't be done that way" is the correct answer -- even if the Asker is not happy with that.  In any case, the suggestions here are worth saving in the PAQ.  

What say we leave it to the Moderator to decide?
-- Dan
0
 
bruintjeCommented:
yes PAQ and refund is ok ...
0
 
SpideyModCommented:
PAQd and points NOT refunded.  Many ideas, much work, most seem content with PAQing, but all points were valid.  You can't do that is an answer, although usually not one well received as is displayed in this thread.  Thanks to everyone for their feedback.  It helped to make the decision.

SpideyMod
Community Support Moderator @Experts Exchange
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 7
  • 4
  • 4
  • +9
Tackle projects and never again get stuck behind a technical roadblock.
Join Now