Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > Beginning VB 6
|
Beginning VB 6 For coders who are new to Visual Basic, working in VB version 6 (not .NET).
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning VB 6 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 9th, 2005, 02:03 PM
Registered User
 
Join Date: Mar 2005
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Determining a Sub or Procedure Name in Code

I've been looking for this answer for years just to satisfy my curiosity and haven't found it. Now I need it.

I want to provide the name of a sub or function procedure in my forms and classes to my error handler.

The easiest approach is to set a variable to a string value at the beginning of each procedure and pass the variable to the error handler.

The minor downsides of this approach are that you have to remember to change that variable if you change the name of the procedure or if you copy and paste code from one procedure to another.

The major downside of this approach right now is that I am working for a client who has some strict coding rules that they enforce. One of which is to not hardcode any strings in procedures.

Now I guess I could make a bunch of constant strings with the values for these procedure names, but I really think there out to be a more elegant and efficient way to do it. I just can't come up with any ideas.

So if the experts could provide instruction or point me to a place where I could see some examples, I would really, really, appreciate it.


 
Old March 9th, 2005, 04:50 PM
Friend of Wrox
 
Join Date: Nov 2004
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default

When a program is compiled, variable names, constant names and function names are tokenized, and eventually turned into addresses or offsets. (Constant references are replaced with the literal values of the constants, still making it so that the name of the constant is gone from the code.)

There simply is no way to do what you are asking.

I would try to explain to the client what it is that you are trying to do, and explain the simplicity and utility of just setting a string variable, as you described. Explain that it does not actually affect the program, only the error reporting contents.

Alternately, perhaps you could hard-code an argument to the error procedure...

(Clients! Life would be so much easier without users!)
 
Old March 9th, 2005, 09:55 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 627
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by BrianWren
(Clients! Life would be so much easier without users!)
Actually: how can I make money without users :(

It is indeed possible to get the current module name using the StackWalk API (that is used in the debugger to show the call stack), but it is not really something I would try in VB. The clients are always right, but that does not mean we cannot talk with them

Marco
 
Old March 10th, 2005, 01:16 PM
Friend of Wrox
 
Join Date: Nov 2004
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default

I think they should just “trust us! It works perfectly! (Hey! Don’t touch!)”

Doesn't that ability work in a compiled program only if the debugging option is enabled in the project properties (Create Symbolic [u]D</u>ebug Info)?





Similar Threads
Thread Thread Starter Forum Replies Last Post
Calling Store Procedure in the PHP Code malay mehta MySQL 0 July 11th, 2007 09:06 AM
Check the strored procedure running in ASP code kapi.goel ASP.NET 1.0 and 1.1 Professional 0 May 17th, 2006 12:19 AM
ASP Code running Stored Procedure kapi.goel ASP.NET 1.0 and 1.1 Basics 0 May 17th, 2006 12:19 AM
Determining the name of function dotnetprogrammer VS.NET 2002/2003 0 October 23rd, 2005 04:46 AM
Running procedure - code window! penta Access 12 February 1st, 2005 04:43 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.