[AccessD] Imitating a STACK

Max Wanadoo max.wanadoo at gmail.com
Wed Jun 24 18:10:32 CDT 2009


Whatever "piece" of code is running, it will have been "called" by a name.
It is that name that we cannot access from VBA

Max



-----Original Message-----
From: accessd-bounces at databaseadvisors.com
[mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Charlotte Foust
Sent: 24 June 2009 23:56
To: Access Developers discussion and problem solving
Subject: Re: [AccessD] Imitating a STACK

But you aren't talking about the module are you?  You want the routine
name.

Charlotte 

-----Original Message-----
From: accessd-bounces at databaseadvisors.com
[mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Max Wanadoo
Sent: Wednesday, June 24, 2009 3:52 PM
To: 'Access Developers discussion and problem solving'
Subject: Re: [AccessD] Imitating a STACK

Aahh.. so it is there..but just not in VBA.

Thank you, Shamil

Ps. Surely there must be an API a programmer could call from VBA which
tells him/her what the .module.name is? No?

Max



-----Original Message-----
From: accessd-bounces at databaseadvisors.com
[mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Shamil
Salakhetdinov
Sent: 24 June 2009 23:42
To: 'Access Developers discussion and problem solving'
Subject: Re: [AccessD] Imitating a STACK

Hi Max,

No, I do not know about any VBA/VB6 code "which "Knows" what the
module/function/sub it is in when it is running it,". But if you're
embedding a tracing call into every your sub and function then you can
just "keep profiling/tracing the running context - the overhead
shouldn't not be that significant I guess...

BTW, in VB.NET/C# your request is performed by using something like that
code:

Console.WriteLine(
"exe={0}\nclass={1}\nmethod={2}",
(new System.Diagnostics.StackFrame()).GetMethod().Module.Name,
(new
System.Diagnostics.StackFrame()).GetMethod().DeclaringType.ToString(),
(new System.Diagnostics.StackFrame()).GetMethod().Name
);

Shamil

-----Original Message-----
From: accessd-bounces at databaseadvisors.com
[mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Max Wanadoo
Sent: Thursday, June 25, 2009 1:30 AM
To: 'Access Developers discussion and problem solving'
Subject: Re: [AccessD] Imitating a STACK

Shamil,

Thanks for that.

I don't suppose you just happen to have any code which "Knows" what the
module/function/sub it is in when it is running it, do you?

I would love to have a line in each that says

Call ShamilsFunction("Enter")

Code

Call ShamilsFunction("Leave")

And in both cases ShamilsFunction KNOWS where it was called
from..without having to expressly state the name.



Max



-----Original Message-----
From: accessd-bounces at databaseadvisors.com
[mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Shamil
Salakhetdinov
Sent: 24 June 2009 22:11
To: 'Access Developers discussion and problem solving'
Subject: Re: [AccessD] Imitating a STACK

<<<
You can only reliably PUSH the STACK and POP the STACK if you have ONE
ENTRY point and ONE EXIT point.
>>>

Hi Max,

Below is a VBA framework to free/"unbind" you from "ONE ENTRY
point and ONE EXIT point" principle - of course just an outline of this
framework, which can be extended much further even to simulate "finally"
constructs of other programming languages - within VBA and with many
exit
points to lighten the coding style: 


' Class Module: MyProfiler
'==============================
Private m_procName As String
Public Sub Init(ByVal procName As String)
    m_procName = procName
    Debug.Print m_procName + ": entry"
End Sub

Private Sub Class_Terminate()
    Debug.Print m_procName + ": exit"
End Sub


' Module: MyProfilerObjectFactory
'=================================
Public Function GetMyProfilerInstance _
    (ByVal procName As String) _
    As MyProfiler
    Dim profiler As New MyProfiler
    profiler.Init procName
    Set GetMyProfilerInstance = profiler
End Function


' Module: MyProfilerTest
'========================

Public Sub entryPoint() ' <= RUN IT
Dim o: Set o = GetMyProfilerInstance("entryPoint")
' ...
sub1
' ...
End Sub
Public Sub sub1()
Dim o: Set o = GetMyProfilerInstance("sub1")
' ...
sub2
' ...
' if something Exit Sub

sub3
' ...
End Sub
Public Sub sub2()
Dim o: Set o = GetMyProfilerInstance("sub2")
' ...
End Sub
Public Sub sub3()
Dim o: Set o = GetMyProfilerInstance("sub3")
' ...
End Sub

' =======


===================
Test output:
===================
entryPoint: entry
sub1: entry
sub2: entry
sub2: exit
sub3: entry
sub3: exit
sub1: exit
entryPoint: exit

--
Shamil


-----Original Message-----
From: accessd-bounces at databaseadvisors.com
[mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Max Wanadoo
Sent: Wednesday, June 24, 2009 11:37 PM
To: 'Access Developers discussion and problem solving'
Subject: Re: [AccessD] Imitating a STACK

Jim,
This is what I was trying to get at when I responded to Arthur's
question re
CallByForm, which wasn't what I was after.

What I have to do to simulate the STACK is to provide a means to record
that
every time I enter a function/sub it is recorded and every time I leave
the
function/sub it is recorded.

You can only reliably PUSH the STACK and POP the STACK if you have ONE
ENTRY
point and ONE EXIT point.

When an error occurs and you are using a error handling routine in a
module/class then it is easy to look at the STACK to identify how you
progressed through the program to the point of the errors. All
functions/subs you encountered on the way are available to you.

I use a Global Boolean variable called gvRecordProgress.  On each
Function/Sub I have a line which says:

Private function myfunctionname
On error goto pfMyGlobalErrorHandler
If gbRecordProgress = true the call pfPushStack("Push","myfunctionname")

Code
Code

Onexit:
If gbRecordProgress = true the call
pfRecordStack("Pop","myfunctionname")
Code
Exit function

End function

Now, before you all go screaming at me, the above is taken from memory
and I
do not have access to Access (!) but you will get the general concept.
The
names have been plucked out of the air.  This is just so that I can
illustrate what I mean.

You can switch it on/off by just changing the value of gbRecordProgress.

This is also a useful way to see which functions/sub are used the most -
ie,
where tightening up of code would result in a big improvement overall.

NOW: To get the two lines in, if you have that little toolset (mxtools
or
something like that) you can tell it to do the above for you and whilst
it
is doing it, it can actually insert the function/sub name into the line,
so
it only takes seconds  Apologies for not remembering the name of the
tool,
but you all know it because you have mentioned it here many times.



Max
Ps. Changed subject.


<<< snip >>
 

__________ Information from ESET NOD32 Antivirus, version of virus
signature
database 4186 (20090624) __________

The message was checked by ESET NOD32 Antivirus.

http://www.esetnod32.ru
 

-- 
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com

-- 
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com

__________ Information from ESET NOD32 Antivirus, version of virus
signature
database 4186 (20090624) __________

The message was checked by ESET NOD32 Antivirus.

http://www.esetnod32.ru


 

__________ Information from ESET NOD32 Antivirus, version of virus
signature
database 4186 (20090624) __________

The message was checked by ESET NOD32 Antivirus.

http://www.esetnod32.ru
 

-- 
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com

-- 
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com

-- 
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com




More information about the AccessD mailing list