Determining the size of a procedure

  • Thread starter Thread starter Janie
  • Start date Start date
J

Janie

I am dancing dangerously close to the 64K limit on a couple of my procedures.
I know when I compile I'll get a message if I've strayed over the magic
number. I was wondering ... is there any way to tell the actual size of the
procedure so I can judge just how close to the edge I really am?
 
What are you calling a "Procedure"? A Sub or a Function? A Class module? A
Standard module?
 
Well, if you are familiar with Access, you should know that a Procedure is
defined as "A named sequence of statements executed as a unit. For example,
Function, Property and Sub are types of procedures. A procedure name is
always defined at module level. All executable code must be contained in a
procedure. Procedures can't be nested within other procedures."

Go to Access' help and enter the word procedure. You can find the
definition there. You can also find the error message labeled "Procedure too
large" which explains the 64K limit.

Anyone else have a useful suggestion?
 
I appreciate the pointers. Why not break your procedure into more than one
procedure and eliminate the potential problem? Certainly procedures can call
other procedures.
Well, if you are familiar with Access, you should know that a Procedure is
defined as "A named sequence of statements executed as a unit. For example,
Function, Property and Sub are types of procedures. A procedure name is
always defined at module level. All executable code must be contained in a
procedure. Procedures can't be nested within other procedures."

Go to Access' help and enter the word procedure. You can find the
definition there. You can also find the error message labeled "Procedure too
large" which explains the 64K limit.

Anyone else have a useful suggestion?
What are you calling a "Procedure"? A Sub or a Function? A Class module? A
Standard module?
[quoted text clipped - 3 lines]
 
Sample code - that I banged together

Public Function fGetProcSize()
Dim strText As String
Dim iStart As Integer
Dim iEnd As Integer

Dim M As Module
Set M = Modules("ModCalcEaster")

iStart = M.ProcBodyLine("EasterHodges", 0)
iEnd = M.ProcCountLines("EasterHodges", 0)
strText = M.Lines(iStart, iEnd)

Debug.Print Len(strText)
'Debug.Print strText

End Function

You will need to generalize it.
--
John Spencer
Access MVP 2002-2005, 2007-2008
Center for Health Program Development and Management
University of Maryland Baltimore County
..
 
it needed one extra line : DoCmd.OpenModule "ModCalcEaster". I placed it
before the set M=Modules(ModCalcEaster). Wuithout that line, it would not
run.

Thanks for the idea.
 
Janie said:
Well, if you are familiar with Access, you should know that a Procedure is
defined as "A named sequence of statements executed as a unit. For
example,
Function, Property and Sub are types of procedures. A procedure name is
always defined at module level. All executable code must be contained in
a
procedure. Procedures can't be nested within other procedures."

Go to Access' help and enter the word procedure. You can find the
definition there. You can also find the error message labeled "Procedure
too
large" which explains the 64K limit.

Anyone else have a useful suggestion?

Well you could use SaveAsText to output a file, edit it to remove extraneous
code, save it, then look at it in explorer for the size...

Application.saveastext acModule,"MyModuleName", _
"C:\temp\MyModuleName.txt"
 
You are missing the point of the question which is how to determine the size
of a procedure. I am aware of how to resolve a procedure that is too large.
That is not what I am trying to do.

ruralguy via AccessMonster.com said:
I appreciate the pointers. Why not break your procedure into more than one
procedure and eliminate the potential problem? Certainly procedures can call
other procedures.
Well, if you are familiar with Access, you should know that a Procedure is
defined as "A named sequence of statements executed as a unit. For example,
Function, Property and Sub are types of procedures. A procedure name is
always defined at module level. All executable code must be contained in a
procedure. Procedures can't be nested within other procedures."

Go to Access' help and enter the word procedure. You can find the
definition there. You can also find the error message labeled "Procedure too
large" which explains the 64K limit.

Anyone else have a useful suggestion?
What are you calling a "Procedure"? A Sub or a Function? A Class module? A
Standard module?
[quoted text clipped - 3 lines]
number. I was wondering ... is there any way to tell the actual size of the
procedure so I can judge just how close to the edge I really am?

--
RuralGuy (RG for short) aka Allan Bunch MS Access MVP - acXP WinXP Pro
Please post back to this forum so all may benefit.

Message posted via AccessMonster.com
 
Thank you John. Pretty slick.

John said:
Sample code - that I banged together

Public Function fGetProcSize()
Dim strText As String
Dim iStart As Integer
Dim iEnd As Integer

Dim M As Module
Set M = Modules("ModCalcEaster")

iStart = M.ProcBodyLine("EasterHodges", 0)
iEnd = M.ProcCountLines("EasterHodges", 0)
strText = M.Lines(iStart, iEnd)

Debug.Print Len(strText)
'Debug.Print strText

End Function

You will need to generalize it.
 
Ok, so I had a few moments last night and tested this and ran into a bit of
a problem. If the module wasn't open, it failed.

Here is my revised code. If I was putting this into production, I would
include error handling. But since I see this as a tool for the designer I
don't really care if it errors because the inputs were incorrect (bad module
name, bad procedure name).

Public Function fGetProcSize(modName As String, procName As String)
Dim iStart As Integer
Dim iEnd As Integer
Dim M As Module
Dim tfCloseModule As Boolean

If IsModuleOpen(modName) = False Then
DoCmd.OpenModule modName
tfCloseModule = True
End If

Set M = Modules(modName)

iStart = M.ProcBodyLine(procName, 0)
iEnd = M.ProcCountLines(procName, 0)

MsgBox "Character count = " & Len(M.Lines(iStart, iEnd))

If tfCloseModule = True Then
DoCmd.Close acModule, modName, acSaveNo
End If

End Function

Private Function IsModuleOpen(strModulename As String) As Boolean
'See if a module is already open
Dim modAny As Module

On Error GoTo IsModuleOpen_ERROR
Set modAny = Modules(strModulename)
IsModuleOpen = True
Exit Function

IsModuleOpen_ERROR:
IsModuleOpen = False
End Function

--
John Spencer
Access MVP 2002-2005, 2007-2008
Center for Health Program Development and Management
University of Maryland Baltimore County
..
 
Yes, I have done that ...I was looking for something less cumbersome. Also
when I did that, the file said it was 60K ... but when I ran the procedure, I
got the "Procedure Too Large" Errror. I ended up using the routine from John.
 
Back
Top