Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Display the current Module or Sub name? 3

Status
Not open for further replies.

jgarry

Programmer
Nov 23, 2004
67
US
Hi, thanks for your assistance. I am looking for a quick way to display the current sub or module name in my program. I want to export this to a text file (no problem) what I need is a way to grab the current module or sub name.

I know that I could create a global var str_sub

then in the sub put the name str_sub = "Main Sub"
then use this in the file.

I would like to know if I can use some object or system variable instead of "Main Sub" just to get the current name.

Thank you again
Jim
 
Nope. That's what you have to do with Debug Print statements as well. Makes global error handling harder.

-David
2006 & 2007 Microsoft Most Valuable Professional (MVP)
2006 Dell Certified System Professional (CSP)
 
Thanks for the replay, I guess it can't be that easy.

Jim
 
I've been using the following code. Not as easy as you wanted but its better than entering it manually in every Sub or Module

I write a separate program that reads the .frm files of my project and writes it to a temp file, when done it deletes the frm file and renames the temp file as the frm file. it inserts the following after reading a line with Private Sub (or Public Sub etc) in it

Example
'I read in each line to d$ and write it to temp.tmp

Open app.path & "\" & Formname for input as #1
Open app.path & "\temp.tmp" for output as #2

while not eof(1)
line input #1, d$
if instr(d$,"Private Sub") > 0 then
print #2, d$
print #2, "dim s as variant"
print #2, "s = split(d$," ")"
print #2, "Open app.path & "\SubEntered.dat" for append as #6"
print #2, "Print #6, left$(s(2), instr(s(2),"(")-1)"
print #2, "close #6"
else
print #2, d$
end if
wend
close
kill app.path & "\" & Formname
name app.path & "\temp.tmp" as app.path & "\" & Formname

WARNING: Test this first before using in your projects. I am not at my main computer and just wrote the above real quick to give you the idea of what I do.
 
Thanks for the assistance. I will use your code.

Jim Garry
 
MZ Tools will do that automatically for you, amongst other things. It's a free add-on for VB6

-David
2006 & 2007 Microsoft Most Valuable Professional (MVP)
2006 Dell Certified System Professional (CSP)
 
I would also recommend using conditional compiling for something like this. For example:
Code:
#const isDebug = True

Public Sub MySub
#if isDebug then
     (yacyac's code goes here)
#end if
End Sub
This way, all you need to do before compiling your production version is change the isDebug constant to False, and none of yacyac's code will be added.

HTH

Bob
 
dglienna thanks for the info on the mz tools

Also BobRodes, that is a good suggestion also. I had just learned about th # stuff a few weeks ago, but had not thought of using it that way.

Thanks to all of you for your assistance
Jim
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top