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

Procedure list

3 views
Skip to first unread message

Armando

unread,
May 26, 2005, 10:34:32 PM5/26/05
to
I get the urge to do this every several years, and in each new language I
get proficient in. I want to write a program that will generate an indented
list (maybe I'll learn about TreeViews later) of the function call structure
of my VB code. In other languages, like C or Pascal, I was going to scan
the entire program to find the function names, then scan again looking for
anywhere those function names are called, keeping track of which one I'm in
at the time. With the code not all contiguous but in various modules, I
can't do it that way, but it looks like I should be able to grab all the
names from a Procedures collection or something. I've looked into it enough
to think I'm close, then the help text blows past it into areas that don't
seem related. Can anyone offer pointers or code snippets to enumerate all
the Functions and Subs in a db? Do I have to hit the modules separately, or
are they all stored together? Etc, etc.

Thanks,

Armando


Salad

unread,
May 27, 2005, 3:26:13 PM5/27/05
to
Armando wrote:

Public Sub ModuleList()
Dim dbs As Database
Dim doc As Document
Set dbs = CurrentDb

With dbs.Containers!Modules
For Each doc In .Documents
AllProcs doc.name
Next
End With
dbs.Close
Set dbs = Nothing
MsgBox "Done"
End Sub

'taken straight out of help example in MS Access. You didn't look in
the right places.
Function AllProcs(strModuleName As String)
Dim mdl As Module
Dim lngCount As Long, lngCountDecl As Long, lngI As Long
Dim strProcName As String, astrProcNames() As String
Dim intI As Integer, strMsg As String
Dim lngR As Long

' Open specified Module object.
DoCmd.OpenModule strModuleName
' Return reference to Module object.
Set mdl = Modules(strModuleName)
' Count lines in module.
lngCount = mdl.CountOfLines
' Count lines in Declaration section in module.

lngCountDecl = mdl.CountOfDeclarationLines
' Determine name of first procedure.
strProcName = mdl.ProcOfLine(lngCountDecl + 1, lngR)
' Initialize counter variable.
intI = 0
' Redimension array.
ReDim Preserve astrProcNames(intI)
' Store name of first procedure in array.
astrProcNames(intI) = strProcName
' Determine procedure name for each line after declarations.
For lngI = lngCountDecl + 1 To lngCount
' Compare procedure name with ProcOfLine property value.

If strProcName <> mdl.ProcOfLine(lngI, lngR) Then
' Increment counter.
intI = intI + 1
strProcName = mdl.ProcOfLine(lngI, lngR)
ReDim Preserve astrProcNames(intI)
' Assign unique procedure names to array.
astrProcNames(intI) = strProcName
End If
Next lngI
strMsg = "Procedures in module '" & strModuleName & "': " _
& vbCrLf & vbCrLf
For intI = 0 To UBound(astrProcNames)
strMsg = strMsg & astrProcNames(intI) & vbCrLf

Next intI
' Dialog box listing all procedures in module.
MsgBox strMsg
End Function

Armando

unread,
May 29, 2005, 6:22:52 PM5/29/05
to
"Salad" <o...@vinegar.com> wrote in message
news:pvKle.806$s64...@newsread1.news.pas.earthlink.net...

> Armando wrote:
> > Can anyone offer pointers or code snippets to enumerate all
> > the Functions and Subs in a db?

> 'taken straight out of help example in MS Access. You didn't look in
> the right places.
> (code deleted)

I guess I didn't. I thought I hit every related topic there was. Thanks
for the info, I'll see what I can do with it.

Armando

Armando

unread,
May 30, 2005, 12:48:41 PM5/30/05
to
Salad,

Now that I look this code over, I think I did come across it in my
wandering. It does indeed do what my question asked, but it turns out I
didn't say it right. I haven't figured out how to get into the Form
modules, where a lot of my code lives.

It's probably just a few tweaks from this code, but I'm still green on the
structure and accessing of the Collections. I need to get another good book
on A2000, I had to leave all my references behind.

Armando


Salad

unread,
May 31, 2005, 10:55:32 AM5/31/05
to
Armando wrote:

Every now and then you have to do some snipping and tucking and
modifying of what you were provided to get the answer.

I have an exitfor at the bottom you can remove if you want to cycle
through all of the forms.

I think with this code you can adjust it to go through Reports.
Unfortunately, Reports does not have an acHidden property in A97, so you
may get some flashing unless you set the echo off.

Sub FormModules()


Dim dbs As Database
Dim doc As Document

Dim frm As Form

Dim lngCount As Long
Dim lngCountDecl As Long
Dim lngI As Long
Dim strProcName As String
Dim astrProcNames() As String
Dim intI As Integer
Dim strMsg As String
Dim lngR As Long

Set dbs = CurrentDb

With dbs.Containers!Forms


For Each doc In .Documents

DoCmd.OpenForm doc.Name, acDesign, , , , acHidden
Set frm = Forms(doc.Name)
' Set form properties.
With frm
lngCount = frm.Module.CountOfLines
lngCountDecl = frm.Module.CountOfDeclarationLines


' Determine name of first procedure.

strProcName = frm.Module.ProcOfLine(lngCountDecl + 1, lngR)


' Initialize counter variable.
intI = 0
' Redimension array.
ReDim Preserve astrProcNames(intI)
' Store name of first procedure in array.
astrProcNames(intI) = strProcName
' Determine procedure name for each line after
declarations.
For lngI = lngCountDecl + 1 To lngCount
' Compare procedure name with ProcOfLine property value.

If strProcName <> frm.Module.ProcOfLine(lngI, lngR)

Then
' Increment counter.
intI = intI + 1

strProcName = frm.Module.ProcOfLine(lngI, lngR)


ReDim Preserve astrProcNames(intI)
' Assign unique procedure names to array.
astrProcNames(intI) = strProcName
End If
Next lngI

strMsg = "Procedures in Form " & doc.Name & " Module: " _


& vbCrLf & vbCrLf
For intI = 0 To UBound(astrProcNames)
strMsg = strMsg & astrProcNames(intI) & vbCrLf

Next intI
' Dialog box listing all procedures in module.
MsgBox strMsg

End With
Set frm = Nothing
DoCmd.Close acForm, doc.Name

'remove this is you want to cycle through all of the forms
Exit For
Next doc
End With

Armando

unread,
May 31, 2005, 4:52:33 PM5/31/05
to
I have been playing with the code you cited last, to help me learn about
Collections, Containers, and how they all interrelate. Drawing a map as I
go. A map that I HAD ONCE!

I went shopping for a reference today, but walked away with sticker shock,
until I can spend enough time making sure I get the right one. Even the
most advanced ones look like they're holding your hand, showing how to
design a Table or Form, and chapters on !! how to use the design wizards !!

Gracias encore...


Salad

unread,
Jun 1, 2005, 10:40:28 AM6/1/05
to
Armando wrote:

A popular book is the Access (version) Developers Guide. If you know
how to code, that would be a good start. It's worth the money if you
are going to code in Access.

I find the best reference available is http://groups.google.com.

About the worst reference for Access in on-line help if you have a
version above A97...MS seemed to go out of their way to may their help
system useless. Some call it MS Helpless.

0 new messages