By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,238 Members | 1,320 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,238 IT Pros & Developers. It's quick & easy.

Procedure list

P: n/a
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
Nov 13 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
Armando wrote:
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

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

Nov 13 '05 #2

P: n/a
"Salad" <oi*@vinegar.com> wrote in message
news:pv***************@newsread1.news.pas.earthlin k.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

Nov 13 '05 #3

P: n/a
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
Nov 13 '05 #4

P: n/a
Armando wrote:
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

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
Set dbs = Nothing
MsgBox "Done"
End Sub
Nov 13 '05 #5

P: n/a
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...
Nov 13 '05 #6

P: n/a
Armando wrote:
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...

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.
Nov 13 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.