Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 171
Default Practical Macro Size Limit?

I'm building a Macro that is growing "like Topsy". At the moment it is 145
lines long, and will increase by about 50% from there when done. Because I'm
an old (really OLD<g) VFP programmer, my thinking and development pattern is
shaped by that experience.

So, is it considered bad form to have a macro get large? I recall that in
C++ the recommendation was to try to hold a process to one screenful where
possible, and then build a "parent" process that called the segments in
sequence. However my macro consists of a series of nested For Loops that goes
five or six levels deep.

Just wondering -- and trying to learn <g!
--
Dave
Temping with Staffmark
in Rock Hill, SC
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 171
Default Practical Macro Size Limit?

I said I was OLD, couldn't remember the word "module" to save my life. Not
ignorance, just a little "Halfzheimer's" <g). Non "Process" est, sed
"Module". Mea culpa <g!
--
Dave
Temping with Staffmark
in Rock Hill, SC


"Dave Birley" wrote:

I'm building a Macro that is growing "like Topsy". At the moment it is 145
lines long, and will increase by about 50% from there when done. Because I'm
an old (really OLD<g) VFP programmer, my thinking and development pattern is
shaped by that experience.

So, is it considered bad form to have a macro get large? I recall that in
C++ the recommendation was to try to hold a process to one screenful where
possible, and then build a "parent" process that called the segments in
sequence. However my macro consists of a series of nested For Loops that goes
five or six levels deep.

Just wondering -- and trying to learn <g!
--
Dave
Temping with Staffmark
in Rock Hill, SC

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Practical Macro Size Limit?

There is a limit of about 64K on the size of a module. You would export it
to a .bas file, then look at the size of the file. The limit is not
published anywhere, but appears to be a practical limit - above that you
start having problems. Beyond that, I don't believe there is any limit.
Some people create huge procedures using the macro recorder.

Use of subroutines is encouraged from a maintenance/readability standpoint.

--
Regards,
Tom Ogilvy



"Dave Birley" wrote:

I said I was OLD, couldn't remember the word "module" to save my life. Not
ignorance, just a little "Halfzheimer's" <g). Non "Process" est, sed
"Module". Mea culpa <g!
--
Dave
Temping with Staffmark
in Rock Hill, SC


"Dave Birley" wrote:

I'm building a Macro that is growing "like Topsy". At the moment it is 145
lines long, and will increase by about 50% from there when done. Because I'm
an old (really OLD<g) VFP programmer, my thinking and development pattern is
shaped by that experience.

So, is it considered bad form to have a macro get large? I recall that in
C++ the recommendation was to try to hold a process to one screenful where
possible, and then build a "parent" process that called the segments in
sequence. However my macro consists of a series of nested For Loops that goes
five or six levels deep.

Just wondering -- and trying to learn <g!
--
Dave
Temping with Staffmark
in Rock Hill, SC

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Practical Macro Size Limit?

Use good programming practives. Usually around 200 - 250 line of code per
module is the limit. Better than the 500 punch cards I had to use in
college. Consider how you are going to tet the code in making the decision
to have one or multiple modules.

You didn't say if you where building a subroutine or a function, but it is
always good to create sub-functions where possible.

"Dave Birley" wrote:

I said I was OLD, couldn't remember the word "module" to save my life. Not
ignorance, just a little "Halfzheimer's" <g). Non "Process" est, sed
"Module". Mea culpa <g!
--
Dave
Temping with Staffmark
in Rock Hill, SC


"Dave Birley" wrote:

I'm building a Macro that is growing "like Topsy". At the moment it is 145
lines long, and will increase by about 50% from there when done. Because I'm
an old (really OLD<g) VFP programmer, my thinking and development pattern is
shaped by that experience.

So, is it considered bad form to have a macro get large? I recall that in
C++ the recommendation was to try to hold a process to one screenful where
possible, and then build a "parent" process that called the segments in
sequence. However my macro consists of a series of nested For Loops that goes
five or six levels deep.

Just wondering -- and trying to learn <g!
--
Dave
Temping with Staffmark
in Rock Hill, SC

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 171
Default Practical Macro Size Limit?

Ok, so to use sub-modules (and I really like that idea), suppose I have this
construct:

Dim blnYunky as Boolean
Dim myParameter as Long
For Each Yadda In Yading To Yadong
If Bingo Then
'what do I put here to call module Fooby with a parameter?
blnYunky = MyModule(myParameter, myResult) '??
Endif

Private Function MyModule (ByRef myParameter As Long, _
myResult As Boolean) As Long
For Each rngWiggy In Range(rngBugfree(1), rngBugFree(myParameter)
'Yadda, yadda
If MySomething Then
MyResult = True
End If
Next rngWiggy
End Function

Is that the sort of thing you mean?
--
Dave
Temping with Staffmark
in Rock Hill, SC


"Joel" wrote:

Use good programming practives. Usually around 200 - 250 line of code per
module is the limit. Better than the 500 punch cards I had to use in
college. Consider how you are going to tet the code in making the decision
to have one or multiple modules.

You didn't say if you where building a subroutine or a function, but it is
always good to create sub-functions where possible.

"Dave Birley" wrote:

I said I was OLD, couldn't remember the word "module" to save my life. Not
ignorance, just a little "Halfzheimer's" <g). Non "Process" est, sed
"Module". Mea culpa <g!
--
Dave
Temping with Staffmark
in Rock Hill, SC


"Dave Birley" wrote:

I'm building a Macro that is growing "like Topsy". At the moment it is 145
lines long, and will increase by about 50% from there when done. Because I'm
an old (really OLD<g) VFP programmer, my thinking and development pattern is
shaped by that experience.

So, is it considered bad form to have a macro get large? I recall that in
C++ the recommendation was to try to hold a process to one screenful where
possible, and then build a "parent" process that called the segments in
sequence. However my macro consists of a series of nested For Loops that goes
five or six levels deep.

Just wondering -- and trying to learn <g!
--
Dave
Temping with Staffmark
in Rock Hill, SC



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Practical Macro Size Limit?

Yes, except MyModule doesn't return anything.

"Dave Birley" wrote:

Ok, so to use sub-modules (and I really like that idea), suppose I have this
construct:

Dim blnYunky as Boolean
Dim myParameter as Long
For Each Yadda In Yading To Yadong
If Bingo Then
'what do I put here to call module Fooby with a parameter?
blnYunky = MyModule(myParameter, myResult) '??
Endif

Private Function MyModule (ByRef myParameter As Long, _
myResult As Boolean) As Long
For Each rngWiggy In Range(rngBugfree(1), rngBugFree(myParameter)
'Yadda, yadda
If MySomething Then
MyResult = True
End If
Next rngWiggy
End Function

Is that the sort of thing you mean?
--
Dave
Temping with Staffmark
in Rock Hill, SC


"Joel" wrote:

Use good programming practives. Usually around 200 - 250 line of code per
module is the limit. Better than the 500 punch cards I had to use in
college. Consider how you are going to tet the code in making the decision
to have one or multiple modules.

You didn't say if you where building a subroutine or a function, but it is
always good to create sub-functions where possible.

"Dave Birley" wrote:

I said I was OLD, couldn't remember the word "module" to save my life. Not
ignorance, just a little "Halfzheimer's" <g). Non "Process" est, sed
"Module". Mea culpa <g!
--
Dave
Temping with Staffmark
in Rock Hill, SC


"Dave Birley" wrote:

I'm building a Macro that is growing "like Topsy". At the moment it is 145
lines long, and will increase by about 50% from there when done. Because I'm
an old (really OLD<g) VFP programmer, my thinking and development pattern is
shaped by that experience.

So, is it considered bad form to have a macro get large? I recall that in
C++ the recommendation was to try to hold a process to one screenful where
possible, and then build a "parent" process that called the segments in
sequence. However my macro consists of a series of nested For Loops that goes
five or six levels deep.

Just wondering -- and trying to learn <g!
--
Dave
Temping with Staffmark
in Rock Hill, SC

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default Practical Macro Size Limit?

To expand on what Tom said. One of the biggest reasons to break up a large
procedure into a set of small procedures is readability. You alluded to that
in your original post. It should all fit on one screen. Debugging is a whole
lot easier on small procedures that do a limited number of things. My general
rule is that one procedure should do one thing. For instance it could format
a sheet or copy some data or print one or more sheets. If I want to do a
bunch of things then I use a main calling procedure to call my format precdue
then copy then print. If I need to debug or modify my code it is easy to
determine which procedure or procedures need to be modified. So in general
you should reach the proctical limit for the size of a procedure long before
you hit an technical limit... Just my 2 cents.

--
HTH...

Jim Thomlinson


"Dave Birley" wrote:

Ok, so to use sub-modules (and I really like that idea), suppose I have this
construct:

Dim blnYunky as Boolean
Dim myParameter as Long
For Each Yadda In Yading To Yadong
If Bingo Then
'what do I put here to call module Fooby with a parameter?
blnYunky = MyModule(myParameter, myResult) '??
Endif

Private Function MyModule (ByRef myParameter As Long, _
myResult As Boolean) As Long
For Each rngWiggy In Range(rngBugfree(1), rngBugFree(myParameter)
'Yadda, yadda
If MySomething Then
MyResult = True
End If
Next rngWiggy
End Function

Is that the sort of thing you mean?
--
Dave
Temping with Staffmark
in Rock Hill, SC


"Joel" wrote:

Use good programming practives. Usually around 200 - 250 line of code per
module is the limit. Better than the 500 punch cards I had to use in
college. Consider how you are going to tet the code in making the decision
to have one or multiple modules.

You didn't say if you where building a subroutine or a function, but it is
always good to create sub-functions where possible.

"Dave Birley" wrote:

I said I was OLD, couldn't remember the word "module" to save my life. Not
ignorance, just a little "Halfzheimer's" <g). Non "Process" est, sed
"Module". Mea culpa <g!
--
Dave
Temping with Staffmark
in Rock Hill, SC


"Dave Birley" wrote:

I'm building a Macro that is growing "like Topsy". At the moment it is 145
lines long, and will increase by about 50% from there when done. Because I'm
an old (really OLD<g) VFP programmer, my thinking and development pattern is
shaped by that experience.

So, is it considered bad form to have a macro get large? I recall that in
C++ the recommendation was to try to hold a process to one screenful where
possible, and then build a "parent" process that called the segments in
sequence. However my macro consists of a series of nested For Loops that goes
five or six levels deep.

Just wondering -- and trying to learn <g!
--
Dave
Temping with Staffmark
in Rock Hill, SC

  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 171
Default Practical Macro Size Limit?

This is all wonderful for my learning curve. Now my naivitee will emerge:
Where do you park the subProcedures? For example I am currently working in
Module1 (Code). If I park my sub-procedures in the same Module, even though I
have made the code easier to read and to debug, am I not still at risk of
hitting that size limit previously mentioned by Tom?

Otherwise, how do I initiate a new Module to stash my sub-Procedures?
--
Dave
Temping with Staffmark
in Rock Hill, SC


"Jim Thomlinson" wrote:

To expand on what Tom said. One of the biggest reasons to break up a large
procedure into a set of small procedures is readability. You alluded to that
in your original post. It should all fit on one screen. Debugging is a whole
lot easier on small procedures that do a limited number of things. My general
rule is that one procedure should do one thing. For instance it could format
a sheet or copy some data or print one or more sheets. If I want to do a
bunch of things then I use a main calling procedure to call my format precdue
then copy then print. If I need to debug or modify my code it is easy to
determine which procedure or procedures need to be modified. So in general
you should reach the proctical limit for the size of a procedure long before
you hit an technical limit... Just my 2 cents.

--
HTH...

Jim Thomlinson


"Dave Birley" wrote:

Ok, so to use sub-modules (and I really like that idea), suppose I have this
construct:

Dim blnYunky as Boolean
Dim myParameter as Long
For Each Yadda In Yading To Yadong
If Bingo Then
'what do I put here to call module Fooby with a parameter?
blnYunky = MyModule(myParameter, myResult) '??
Endif

Private Function MyModule (ByRef myParameter As Long, _
myResult As Boolean) As Long
For Each rngWiggy In Range(rngBugfree(1), rngBugFree(myParameter)
'Yadda, yadda
If MySomething Then
MyResult = True
End If
Next rngWiggy
End Function

Is that the sort of thing you mean?
--
Dave
Temping with Staffmark
in Rock Hill, SC


"Joel" wrote:

Use good programming practives. Usually around 200 - 250 line of code per
module is the limit. Better than the 500 punch cards I had to use in
college. Consider how you are going to tet the code in making the decision
to have one or multiple modules.

You didn't say if you where building a subroutine or a function, but it is
always good to create sub-functions where possible.

"Dave Birley" wrote:

I said I was OLD, couldn't remember the word "module" to save my life. Not
ignorance, just a little "Halfzheimer's" <g). Non "Process" est, sed
"Module". Mea culpa <g!
--
Dave
Temping with Staffmark
in Rock Hill, SC


"Dave Birley" wrote:

I'm building a Macro that is growing "like Topsy". At the moment it is 145
lines long, and will increase by about 50% from there when done. Because I'm
an old (really OLD<g) VFP programmer, my thinking and development pattern is
shaped by that experience.

So, is it considered bad form to have a macro get large? I recall that in
C++ the recommendation was to try to hold a process to one screenful where
possible, and then build a "parent" process that called the segments in
sequence. However my macro consists of a series of nested For Loops that goes
five or six levels deep.

Just wondering -- and trying to learn <g!
--
Dave
Temping with Staffmark
in Rock Hill, SC

  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default Practical Macro Size Limit?

Here is a sample of how modular code can work in VBA. The first one is the
control
sub which calls the others in the order they need to run. The sub routines
are listed in order but they don't have to be. They can be anywhere in the
standard module.

Sub addErase()
addCellValue
moveCellVaule
changeCellValue
delCellValue
End SuB

Sub addCellValue()
Range("A1") = "Hello"
End Sub

Sub moveCellValue()
Range("A1").Value.Cut Range("B1")
Application.CutCopyMode = False
End Sub

Sub changeCellValue()
Range("B1").Value = Range("B1").Value & "World"
End Sub

Sub delCellValue()
Range("B1").Clear
ThisWorkbook.Save
ThisWorkbook.Close
End Sub


"Dave Birley" wrote:

I'm building a Macro that is growing "like Topsy". At the moment it is 145
lines long, and will increase by about 50% from there when done. Because I'm
an old (really OLD<g) VFP programmer, my thinking and development pattern is
shaped by that experience.

So, is it considered bad form to have a macro get large? I recall that in
C++ the recommendation was to try to hold a process to one screenful where
possible, and then build a "parent" process that called the segments in
sequence. However my macro consists of a series of nested For Loops that goes
five or six levels deep.

Just wondering -- and trying to learn <g!
--
Dave
Temping with Staffmark
in Rock Hill, SC

  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 171
Default Practical Macro Size Limit?

Thank you (and everyone) for all the help on this. As I am primarily a
"practical" (vs. "theoretical") learner, the example you gave was a huge
help. I really appreciate everyone's patience with me <g!
--
Dave
Temping with Staffmark
in Rock Hill, SC


"JLGWhiz" wrote:

Here is a sample of how modular code can work in VBA. The first one is the
control
sub which calls the others in the order they need to run. The sub routines
are listed in order but they don't have to be. They can be anywhere in the
standard module.

Sub addErase()
addCellValue
moveCellVaule
changeCellValue
delCellValue
End SuB

Sub addCellValue()
Range("A1") = "Hello"
End Sub

Sub moveCellValue()
Range("A1").Value.Cut Range("B1")
Application.CutCopyMode = False
End Sub

Sub changeCellValue()
Range("B1").Value = Range("B1").Value & "World"
End Sub

Sub delCellValue()
Range("B1").Clear
ThisWorkbook.Save
ThisWorkbook.Close
End Sub


"Dave Birley" wrote:

I'm building a Macro that is growing "like Topsy". At the moment it is 145
lines long, and will increase by about 50% from there when done. Because I'm
an old (really OLD<g) VFP programmer, my thinking and development pattern is
shaped by that experience.

So, is it considered bad form to have a macro get large? I recall that in
C++ the recommendation was to try to hold a process to one screenful where
possible, and then build a "parent" process that called the segments in
sequence. However my macro consists of a series of nested For Loops that goes
five or six levels deep.

Just wondering -- and trying to learn <g!
--
Dave
Temping with Staffmark
in Rock Hill, SC



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
limit on size of macro for excell97 Joe Farruggio Excel Discussion (Misc queries) 1 September 18th 06 04:45 AM
Array size limit Myles[_69_] Excel Programming 19 August 16th 06 08:09 PM
Cell size? Or size limit for Text data type? CClem Excel Discussion (Misc queries) 0 April 21st 06 04:09 PM
Size Limit for ADO query? cesw[_3_] Excel Programming 3 September 13th 05 02:24 AM
Macro Size Limit / open macros with macros? andycharger[_7_] Excel Programming 6 February 13th 04 02:00 PM


All times are GMT +1. The time now is 03:52 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"