Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Call Stack

117 views
Skip to first unread message

Paul

unread,
Jul 29, 2002, 12:03:28 AM7/29/02
to
Is there a way to access the information about the call
stack and vb locals from vb code?

Thanks in advance.

Bernard Shifman

unread,
Jul 29, 2002, 12:23:51 AM7/29/02
to
RTFM, pal.


"Paul" <reb...@hotmail.com> wrote in message
news:1fef01c236b4$e5460660$37ef2ecf@TKMSFTNGXA13...

Ken Halter

unread,
Jul 29, 2002, 12:26:18 AM7/29/02
to
Nothing built in to give you this functionality... See:

Get Debug Info From Production Apps
http://www.fawcette.com/vsm/2002_05/magazine/columns/blackbelt/

That won't give you any info on the Locals window... only call stack.

--
Ken Halter - MS-MVP-VB - Please keep it in the groups..
http://www.vbsight.com/ - http://www.vbsight.com/MultiColumn.htm

Michael Culley

unread,
Jul 29, 2002, 12:43:40 AM7/29/02
to
Bit harsh, you could send that same reply to any question here.

--
Michael Culley
www.vbdotcom.com


"Bernard Shifman" <ber...@shifmanconsulting.com> wrote in message
news:uO16gerNCHA.1660@tkmsftngp08...

Grinder

unread,
Jul 29, 2002, 12:52:55 AM7/29/02
to
> "Paul" wrote:
> > Is there a way to access the information about the call
> > stack and vb locals from vb code?

"Bernard Shifman" wrote:
> RTFM, pal.

What manual describes how to do this?


Bernard Shifman

unread,
Jul 29, 2002, 1:03:43 AM7/29/02
to
If you don't know that, what are you doing posting messages on this forum,
you moron


"Grinder" <gri...@no.spam.maam.com> wrote in message
news:##4tWxrNCHA.1632@tkmsftngp13...

Michael Culley

unread,
Jul 29, 2002, 1:21:21 AM7/29/02
to
Bernard, you are not a very good troll, you try too hard.

--
Michael Culley
www.vbdotcom.com


Les F.

unread,
Jul 29, 2002, 1:26:15 AM7/29/02
to
You had better re-read the original post.
The "manual" describes how to access the stack
via the IDE. Nowhere does it describe how to
do so via code.

Unless you got the
special
just for "Bernard Shifman"
exclude the rest of us
"manual"

Les F

"Bernard Shifman" <ber...@shifmanconsulting.com> wrote in message news:OzJHz0rNCHA.1660@tkmsftngp08...

unch

unread,
Jul 29, 2002, 1:25:20 AM7/29/02
to
Bernard Shifman wrote:
> If you don't know that, what are you doing posting messages on this forum,
> you moron
>

Take it easy, given the fact that IDE Call Stack window isn't even that
complete, this question is not so simple as RTM.

Michael Culley

unread,
Jul 29, 2002, 1:41:52 AM7/29/02
to
Seeing bernard is so smart, maybe he should explain how to get the locals
info from code. I'm very interested to know.

--
Michael Culley
www.vbdotcom.com


"Les F." <zala underscore at hot mail dot com> wrote in message
news:Oecix$rNCHA.2036@tkmsftngp09...

Grinder

unread,
Jul 29, 2002, 1:49:26 AM7/29/02
to

"Bernard Shifman" <ber...@shifmanconsulting.com> wrote in
message news:OzJHz0rNCHA.1660@tkmsftngp08...
> If you don't know that, what are you doing posting messages
on this forum,
> you moron

Which manual describes how to "access ... the call stack and vb
locals _from vb code_?"


Paul

unread,
Jul 29, 2002, 1:57:44 AM7/29/02
to
I think little Bernard has seen the errors in his ways.

I'm sure he is getting hammered at the moment outside this
newsgroup thread. Because he is not so clever as to expose
to everyone his real email address.

>.
>

Dead

unread,
Jul 29, 2002, 2:04:37 AM7/29/02
to

http://www.petemoss.com/spamflames/ShifmanIsAMoronSpammer.html

"Bernard Shifman" <ber...@shifmanconsulting.com> wrote in message
news:OzJHz0rNCHA.1660@tkmsftngp08...

Adam D. Barratt

unread,
Jul 29, 2002, 2:07:56 AM7/29/02
to
Michael Culley <mcu...@optushome.com.au> wrote:
> Seeing bernard is so smart, maybe he should explain how to get the locals
> info from code. I'm very interested to know.

Is that before or after he explains why he has to spam in an attempt to
get work?

<URL:http://www.petemoss.com/spamflames/ShifmanIsAMoronSpammer.html>

Surprised at least one other poster hadn't made the connection...

Adam
--
I'm glad I was not born before tea.
-- Sidney Smith (1771-1845)

Grinder

unread,
Jul 29, 2002, 2:12:03 AM7/29/02
to

"Adam D. Barratt" <usenet...@adam-barratt.org.uk> wrote in
message news:3d44...@aubergine.my-net-space.net...

> Michael Culley <mcu...@optushome.com.au> wrote:
> > Seeing bernard is so smart, maybe he should explain how to
get the locals
> > info from code. I'm very interested to know.
>
> Is that before or after he explains why he has to spam in an
attempt to
> get work?
>
>
<URL:http://www.petemoss.com/spamflames/ShifmanIsAMoronSpammer.
html>
>
> Surprised at least one other poster hadn't made the
connection...

$3 bucks says it isn't him.


Michael Culley

unread,
Jul 29, 2002, 2:19:14 AM7/29/02
to
> <URL:http://www.petemoss.com/spamflames/ShifmanIsAMoronSpammer.html>

LOL! This guy must be a real jurk to attract that much attention to himself.

> Surprised at least one other poster hadn't made the connection...

They did, 3 minutes before you :)

--
Michael Culley
www.vbdotcom.com


"Adam D. Barratt" <usenet...@adam-barratt.org.uk> wrote in message
news:3d44...@aubergine.my-net-space.net...

Dead

unread,
Jul 29, 2002, 2:22:23 AM7/29/02
to
Not only made the connection, but I've been spammed by him as a consequence
of posting here.


"Adam D. Barratt" <usenet...@adam-barratt.org.uk> wrote in message
news:3d44...@aubergine.my-net-space.net...

Grinder

unread,
Jul 29, 2002, 2:33:16 AM7/29/02
to

"Dead" <de...@nospam.net> wrote in message
news:Q3519.46497$Hj3.1...@newsfeeds.bigpond.com...

> Not only made the connection, but I've been spammed by him as
a consequence
> of posting here.

Very wierd -- you and "Bernard Shifman" are posting from the
same host? He might even be in the room with you?


Bob O`Bob

unread,
Jul 29, 2002, 2:37:02 AM7/29/02
to
Bernard Shifman wrote:
>
> If you don't know that, what are you doing posting messages on this forum,
> you moron


Funny how a google search on simply the single word "moron"
actually turns up "Bernard Shifman" in position #3

Bob
--
VB expert looking for work <http://resumes.dice.com/bobobob>

Dead

unread,
Jul 29, 2002, 3:22:37 AM7/29/02
to
Well that pins us down to one continent, anyway.


"Grinder" <gri...@no.spam.maam.com> wrote in message

news:OhsXbpsNCHA.2624@tkmsftngp08...

Michael Culley

unread,
Jul 29, 2002, 3:25:27 AM7/29/02
to
> Funny how a google search on simply the single word "moron"
> actually turns up "Bernard Shifman" in position #3

LOL! This thread has been the most entertainting I've read in a while.

--
Michael Culley
www.vbdotcom.com


Adam D. Barratt

unread,
Jul 29, 2002, 3:37:22 AM7/29/02
to
Michael Culley <mcu...@optushome.com.au> wrote:
[...]

>> Surprised at least one other poster hadn't made the connection...
>
> They did, 3 minutes before you :)

Not actually the one I was thinking of, who did, but half an hour
later. (IYSWIM)

Anyway, Dead's article didn't arrive on my news spool until after I'd
posted; my server's busy enough without receiving microsoft.* more
frequently than every 10 minutes <g>.

Adam
--
"There is nothing so deadly as not to hold up to people the opportunity
to do great and wonderful things, if we wish to stimulate them in an
active way."
-- Dr. Harold Urey, Nobel Laureate in chemistry

Tony Proctor

unread,
Jul 29, 2002, 4:46:15 AM7/29/02
to
Wow! I'm glad I did get those responses back to myself. Just when I thought
everyone on these newsgroups were helpful friendly soles. :-0

I've had a lot of experience with accessing call stacks, and symbol tables,
programmatically -- but not with VB I'm afraid. However, I can tell you that
even with C/C++ it's a significant development effort, and it can just as
difficult keeping the code in-step with future releases of the
compiler/debugger.

I've written code to walk the stack and generate symbolic stack traces (a
little like the call-stack window in the VB IDE but with
locals/arguments/etc per call frame) on NT (Intel & alpha), VMS (vax and
alpha), and lots of UNIX platforms. This was to generate logs for field
support of a very large program that incorporated structured exception
handling. Since the program almost never "crashed", logs were generated for
any internal error condition (including access violations, etc) to allow
the support organisation to diagnose and fix them.

The only vendors to offer libraries for walking their stacks (i.e. to ensure
consistent access to information in call frames, procedure descriptors, and
elsewhere) were HP and DEC/Compaq (for all their Alpha AXP O/S). All the
others had to be done by-hand, and often incorporating a bit of assembler
where there was no other choice. Intel has one of the more straightforward
stack formats (assuming the BP frame pointer hasn't been optimised away as a
general-purpose register). Debug symbol tables were another problem. There
are a number of standard formats around, e.g. ELF, COFF, but also a lot of
proprietary ones.

Such a feature would be extremely useful for large VB programs, for the
reasons I explained above, but I don't know of any such support. The view
seems to be that only developers want to see the stack, and only via the
IDE.

Tony

(hope I haven't bored you with this)

"Paul" <reb...@hotmail.com> wrote in message
news:1fef01c236b4$e5460660$37ef2ecf@TKMSFTNGXA13...

Mark Jerde

unread,
Jul 29, 2002, 10:32:39 AM7/29/02
to
Tony,

> Such a feature would be extremely useful for large VB programs, for the
> reasons I explained above, but I don't know of any such support. The view
> seems to be that only developers want to see the stack, and only via the
> IDE.

I do it the ugly way, by pushing the procedure name on a stack in the
beginning of the sub or function & popping it when I leave (via a CPushPop
object going out of scope). Ugly, but it allows error handling as posted
below the sig.

Mark Jerde
Biometrics - www.idtechpartners.com


================Begin===============

Scenario Control Application Application Error Information
====================================
Current Time : 7/26/2002 4:53:42 PM
Error String : Object variable or With block variable not set
Error Number : 91
Error Line : 210
Error Procedure : frmSCA.DataToComm

Procedure Stack
---------------
00 frmSCA.cmdEnroll_Click
01 frmSCA.DoIt
02 frmSCA.cmdCancelAuth_Click
03 frmSCA.DataToComm

=================End================


Mark Jerde

unread,
Jul 29, 2002, 10:50:11 AM7/29/02
to

> Scenario Control Application Application Error Information

'
' TODO: In CErrHandler.Init, append just "Error Information"
' if the last word of the program is "Application"
'


Michael Culley

unread,
Jul 29, 2002, 6:33:51 PM7/29/02
to
Mark,

This info can be gained without executing any code until after an error has
occurred. Code is something like this:

Public Property Get Item(Index As Variant) As Allocation
On Error GoTo Fail

Set Item = mBaseParent.Item(Index)

Exit Property
Fail:
ErrReport.AddToStackRaiseError TypeName(Me), "Item[GET]"
End Property

and the error handling results will be something like this

Date/Time: 08:28:39 30-Jul-2002
App: First Class 2000
Version: 3.00.289
Error Number: -2147218492
Error Desc: Item not found in this collection.
Stack Dump: First Class 2000.frmGridReport.heGrid1_DblClick.Line1
First Class 2000.frmGridReport.DrillDown.Line5

FC2kDLL.GridReportExtrasDailySummary.IGridReport_GetDrillDown.Line12
FC2kDLL.GridReportStudents.Refresh.Line3
FC2kDLL.YearLevels.Item[GET].Line1

--
Michael Culley
www.vbdotcom.com


Greg Linwood

unread,
Jul 30, 2002, 1:28:10 AM7/30/02
to
I gave in to doing it manually years ago b/c I usually want key paramter and
internal procedure variable values on top of the basic stack call tree.
Obviously, for any application with significant support requirements, this
info can be invaluable. I use a collection class of cProcedure objects and
include the ability to toggle aspects of the whole thing on / off for
performance purposes.

Cheers,
Greg Linwood

Ken Halter

unread,
Jul 30, 2002, 11:00:19 AM7/30/02
to
That's funny! Just hope his "potential employers" don't think to search the
web for his name <g> He'll be taking over Bill Murrays job as a grounds
keeper on a golf course.

--
Ken Halter - MS-MVP-VB - Please keep it in the groups..

http://www.vbsight.com - http://www.vbsight.com/MultiColumn.htm

Mark Jerde

unread,
Jul 30, 2002, 7:16:00 PM7/30/02
to
Michael,

> This info can be gained without executing any code until after an error has
> occurred. Code is something like this:

I looked at for 30 seconds & don't see what's what. I'll come back & look at
it later.

I also use my CErrHandler for "Warnings" and logging things that go bump in
programs, not just runtime errors. So I still need to maintain my own call
stact.

BTW, CodeSMART makes it easy to put in the sub & function names.

Michael Culley

unread,
Jul 30, 2002, 7:48:18 PM7/30/02
to
> I also use my CErrHandler for "Warnings" and logging things that go bump
in
> programs, not just runtime errors. So I still need to maintain my own
call
> stact.

In those cases I don't need the call stack, but this is probably a matter of
preference.

> BTW, CodeSMART makes it easy to put in the sub & function names.

I have a similar addin which also checks that the error handling code is
correct, eg it gives a warning if the function name has been changed without
changing the corresponding string in the error handling code.

--
Michael Culley
www.vbdotcom.com


"Mark Jerde" <mark....@NOSPAMverizon.net> wrote in message
news:VA.000000c...@nospamverizon.net...

Grinder

unread,
Jul 30, 2002, 11:38:13 PM7/30/02
to

"Paul" <reb...@hotmail.com> wrote in message
news:1fef01c236b4$e5460660$37ef2ecf@TKMSFTNGXA13...
> Is there a way to access the information about the call
> stack and vb locals from vb code?

I don't know if you're still around, Paul, but here's some
add-in code for you. I've just included what you would put
with your add-in code, so if you have difficulties building an
add-in, let me know.

If you call UpdateReflection with a VBE instance (retrieved
when your add-in is connected,) the routine will add textual
constants at the procedural and module-level.

RemoveReflection will clean up thos references.


'Standard Module: Reflection.bas _______________________

Option Explicit

'Requires: VBIDE

Public Enum ReflectionCommand
refRemove
refUpdate
refPopToTop 'refUpdate does replacement of lowest match
End Enum

'leave these alone
Private Const SIGNATURE_MODULE_NAME = "[LowRent.ModuleName]"
Private Const SIGNATURE_PROCEDURE_NAME =
"[LowRent.ProcedureName]"

'change or parameterize these if you like
Private Const CONST_MODULE_NAME = "refModuleName"
Private Const CONST_PROCEDURE_NAME = "refProcedureName"

Public Function ReflectionModuleName(ByVal Code As
VBIDE.CodeModule) As String
Const DELIM = "."
ReflectionModuleName = Code.Parent.Collection.Parent.Name &
DELIM & Code.Parent.Name
End Function

Public Function ReflectionProcedureName(ByVal Member As
VBIDE.Member, Optional ByVal Kind As VBIDE.vbext_ProcKind =
vbext_pk_Proc) As String
Const DELIM = "|"
Select Case Member.Type
Case vbext_mt_Property
Select Case Kind
Case vbext_pk_Get
ReflectionProcedureName = Member.Name & DELIM & "Get"
Case vbext_pk_Let
ReflectionProcedureName = Member.Name & DELIM & "Let"
Case vbext_pk_Set
ReflectionProcedureName = Member.Name & DELIM & "Set"
Case Else
ReflectionProcedureName = Member.Name
End Select
Case vbext_mt_Method
ReflectionProcedureName = Member.Name
Case Else
ReflectionProcedureName = Member.Name
End Select
End Function

Public Sub RemoveReflection(ByVal VBE As VBIDE.VBE)
ExecuteReflection VBE, refRemove
End Sub

Public Sub UpdateReflection(ByVal VBE As VBIDE.VBE, Optional
ByVal TabWidth As Long = 2)
ExecuteReflection VBE, refUpdate, TabWidth
End Sub

Private Sub ExecuteReflection(ByVal VBE As VBIDE.VBE, ByVal
Command As ReflectionCommand, Optional ByVal TabWidth As Long =
2)
Dim oProject As VBIDE.VBProject
Dim oComponent As VBIDE.VBComponent
Dim oCode As VBIDE.CodeModule
Dim oMember As VBIDE.Member

For Each oProject In VBE.VBProjects
For Each oComponent In oProject.VBComponents
Set oCode = oComponent.CodeModule
If Not (oCode Is Nothing) Then
'update module name constants
ExecuteReflection_Module oCode, Command, TabWidth

'update procedure name constants
For Each oMember In oCode.Members
Select Case oMember.Type
Case vbext_mt_Method
ExecuteReflection_Procedure oMember, vbext_pk_Proc,
Command, TabWidth

Case vbext_mt_Property
ExecuteReflection_Procedure oMember, vbext_pk_Get,
Command, TabWidth
ExecuteReflection_Procedure oMember, vbext_pk_Let,
Command, TabWidth
ExecuteReflection_Procedure oMember, vbext_pk_Set,
Command, TabWidth

End Select
Next oMember

End If
Next oComponent
Next oProject

End Sub

Private Sub ExecuteReflection_Module(ByVal Code As CodeModule,
ByVal Command As ReflectionCommand, Optional ByVal TabWidth As
Long = 2)
Dim iStart As Long
Dim iLine As Long
Dim sLine As String
Dim bReplaced As Boolean

sLine = "Private Const " & CONST_MODULE_NAME & " = "
sLine = sLine & """" & ReflectionModuleName(Code) & """"
sLine = sLine & " '" & SIGNATURE_MODULE_NAME
bReplaced = False

For iLine = Code.CountOfDeclarationLines To 1 Step -1
If SIGNATURE_MODULE_NAME = ExtractComment(Code.Lines(iLine,
1)) Then
If (Command <> refUpdate) Or bReplaced Then
Call Code.DeleteLines(iLine, 1)
Else
Call Code.ReplaceLine(iLine, sLine)
bReplaced = True
End If
End If
Next iLine

If (Command <> refRemove) And Not bReplaced Then
Call Code.InsertLines(1, sLine)
End If
End Sub

Private Sub ExecuteReflection_Procedure(ByVal Member As Member,
ByVal Kind As vbext_ProcKind, ByVal Command As
ReflectionCommand, Optional ByVal TabWidth As Long = 2)
Dim oCode As CodeModule
Dim iStart As Long
Dim iLine As Long
Dim sLine As String
Dim bReplaced As Boolean

iStart = ProcInnerLine(Member, Kind)

If iStart > 0 Then
Set oCode = Member.Collection.Parent

sLine = String$(TabWidth, " ")
sLine = sLine & "Const " & CONST_PROCEDURE_NAME & " = "
sLine = sLine & """" & ReflectionProcedureName(Member,
Kind) & """"
sLine = sLine & " '" & SIGNATURE_PROCEDURE_NAME

For iLine = iStart + oCode.ProcCountLines(Member.Name,
Kind) - 1 To iStart Step -1
If SIGNATURE_PROCEDURE_NAME =
ExtractComment(oCode.Lines(iLine, 1)) Then
If (Command <> refUpdate) Or bReplaced Then
Call oCode.DeleteLines(iLine, 1)
Else
Call oCode.ReplaceLine(iLine, sLine)
bReplaced = True
End If
End If
Next iLine

If (Command <> refRemove) And Not bReplaced Then
Call oCode.InsertLines(iStart, sLine)
End If
End If
End Sub

Private Function ProcInnerLine(ByVal Member As VBIDE.Member,
ByVal Kind As vbext_ProcKind) As Long
Dim iLine As Long
Dim iBody As Long
Dim oCode As VBIDE.CodeModule

On Error GoTo Crud:
Set oCode = Member.Collection.Parent

Select Case Member.Type
Case vbext_mt_Property
If Kind <> vbext_pk_Proc Then
iBody = oCode.ProcBodyLine(Member.Name, Kind)
Else
iBody = 0
End If
Case vbext_mt_Method
iBody = oCode.ProcBodyLine(Member.Name, vbext_pk_Proc)
End Select

'skip declaration line (including line continuations)
If (iBody > 0) And Not (oCode Is Nothing) Then
For iLine = iBody To oCode.CountOfLines - 1
If Right$(Trim$(oCode.Lines(iLine, 1)), 1) <>
vbSyntaxLineContinuation Then
ProcInnerLine = iLine + 1
Exit Function
End If
Next iLine
End If

Crud:
ProcInnerLine = 0

End Function

'Standard Module: VbSyntax _______________________________

Option Explicit

Public Const vbSyntaxLineContinuation = "_"
Public Const vbSyntaxInlineComment = "'"

Public Function ExtractComment(ByVal Line As String) As String
Dim iFind As Long

iFind = FindComment(Line)
If iFind > 0 Then
ExtractComment = Mid$(Line, iFind + 1)
Else
ExtractComment = ""
End If

ExtractComment = ""
End Function

Public Function FindComment(ByVal Line As String) As Long
Dim i As Long
Dim bQuote As Boolean

bQuote = False

For i = 1 To Len(Line)
Select Case Mid$(Line, i, 1)
Case """"
bQuote = Not bQuote
Case Else
If Not bQuote Then
If Mid$(Line, i, Len(vbSyntaxInlineComment)) =
vbSyntaxInlineComment Then
FindComment = i
Exit Function
End If
End If
End Select
Next i

FindComment = 0
End Function

paul rebelo

unread,
Jul 31, 2002, 9:25:41 PM7/31/02
to
Thanks Grinder!

It turned out that Bernie did me a great favour in attracting so much
attention to this topic. I'm sure alot of other people benefited from
it, if not then they were certainly entertained. Your contribution was
well recieved.

Regards
Paul Rebelo.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Grinder

unread,
Jul 31, 2002, 11:18:43 PM7/31/02
to

"paul rebelo" <reb...@hotmail.com> wrote in message
news:uHYeapPOCHA.2036@tkmsftngp09...

> Thanks Grinder!
>
> It turned out that Bernie did me a great favour in attracting
so much
> attention to this topic. I'm sure alot of other people
benefited from
> it, if not then they were certainly entertained. Your
contribution was
> well recieved.

Great -- if you find a snag in the logic, let me know in this
forum. It's not very complicated, but I tried to take pains to
account line continuations, user editing, etc.

0 new messages