Solved

Error in VB

Posted on 2002-05-16
31
153 Views
Last Modified: 2010-05-02
How can I determine name of a module and a sub or a function where an error occurred?

thanks
kloppa
0
Comment
Question by:kloppa
  • 7
  • 4
  • 4
  • +9
31 Comments
 
LVL 4

Expert Comment

by:gencross
ID: 7014416
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
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 7014417
Use Error Handling and add the name of the module and procedure in your Error Handling code.

Anthony
0
 
LVL 44

Expert Comment

by:bruintje
ID: 7014441
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
 

Author Comment

by:kloppa
ID: 7014454
thanks for your responses.

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

thanks,
kloppa
0
 
LVL 69

Expert Comment

by:Éric Moreau
ID: 7014459
>>but i am looking for the ways to get that data without having to write it manualy.

This can't be done.
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 7014482
>>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
 

Author Comment

by:kloppa
ID: 7014524
I am just trying to be a good boy and to avoid hardcoding :)

kloppa
0
 
LVL 4

Expert Comment

by:gencross
ID: 7014538
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
 

Author Comment

by:kloppa
ID: 7014563
how can i split the points between you all? :)

kloppa
0
 
LVL 5

Expert Comment

by:rpai
ID: 7014564
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
 
LVL 1

Expert Comment

by:pjbaratelli
ID: 7014757
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
 
LVL 1

Expert Comment

by:carpediem
ID: 7014764
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
 
LVL 1

Expert Comment

by:carpediem
ID: 7014768
Here is a link to the actual product homepage
http://www.compuware.com/products/devpartner/visualbasic/failsafevb.htm
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 7015022
acperkins wrotes:
"Sometimes as developers we have to write code.

Anthony"
you're kidding, aren't you?
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 7015299
Richie,

Muy chistoso! (Translation: Very funny!)

Anthony
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 44

Expert Comment

by:Arthur_Wood
ID: 7015421
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
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 7015452
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
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 7016277
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
 

Author Comment

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

kloppa

0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 7022575
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
 
LVL 44

Expert Comment

by:bruintje
ID: 7023202
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
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 7024279
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
 
LVL 44

Expert Comment

by:bruintje
ID: 7026237
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
 
LVL 69

Expert Comment

by:Éric Moreau
ID: 7026632
>>i'll leave it there

You should at least ask the community support to refund points and move to the PAQ.
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 7027015
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
 
LVL 69

Expert Comment

by:Éric Moreau
ID: 7027115
>>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
 
LVL 49

Expert Comment

by:DanRollins
ID: 7817742
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
 
LVL 69

Expert Comment

by:Éric Moreau
ID: 7817822
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
 
LVL 49

Expert Comment

by:DanRollins
ID: 7818751
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
 
LVL 44

Expert Comment

by:bruintje
ID: 7818761
yes PAQ and refund is ok ...
0
 

Accepted Solution

by:
SpideyMod earned 0 total points
ID: 7909680
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now