[AccessD] Imitating a STACK

Shamil Salakhetdinov shamil at smsconsulting.spb.ru
Wed Jun 24 16:11:22 CDT 2009


<<<
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
 




More information about the AccessD mailing list