#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default ending subs

just a quickie, I have a lot of subs that call other subs. I usually
do this at the bottom of the sub i.e

sub example()

various code

call example2

end sub


by doing this does the example sub stay active until example 2 sub has
ended, if so if i have afew of these going on does it become a drain on
the programs performance. if so is there a way of ending example sub
from example2 as i have no more need for it

regards

Tammy

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 703
Default ending subs

Does the higher sub stay "active"? No. When the nested sub completes the
higher sub regains focus and execution continues at the line after the call
statement. This is not a drain on the system because the higher sub pauses
until the called routine completes.

P.S. you can also call subroutines without the "call" statement. But when
you leave out the "call" keyword you must also leave out the parentheses
surrounding any args. The following examples are different syntax to do
exactly the same thing:

Call DoThis(txt, "hello", Yes, ipos)
DoThis txt, "hello", Yes, ipos


" wrote:

just a quickie, I have a lot of subs that call other subs. I usually
do this at the bottom of the sub i.e

sub example()

various code

call example2

end sub


by doing this does the example sub stay active until example 2 sub has
ended, if so if i have afew of these going on does it become a drain on
the programs performance. if so is there a way of ending example sub
from example2 as i have no more need for it

regards

Tammy


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 983
Default ending subs

Charlie's answer is correct. Just to add my two cents, think of procedures
and functions like building blocks. When you call a sub or function you place
that block onto the stack. If a sub calls another sub or function then that
sub or function is placed on the stack. Blocks can only be removed from the
stack when there is no block on top of them and they are finished. So no you
can not remove the calling block because the called block is sitting on top
of it. Here is where things get interesting. If you make a call within a loop
that executes for example 1000 times then the block needs to be placed on the
stack and taken off the stack 1000 times. If you have an overriding need for
speed (not too often but it can happen) then instead of calling a procedure,
place the code for the called procedure right in the calling procedure
(referred to as inlinning your code). Now you are not having to add and
remove the block 1000 times. ONLY do this if you NEED extra speed.

HTH

" wrote:

just a quickie, I have a lot of subs that call other subs. I usually
do this at the bottom of the sub i.e

sub example()

various code

call example2

end sub


by doing this does the example sub stay active until example 2 sub has
ended, if so if i have afew of these going on does it become a drain on
the programs performance. if so is there a way of ending example sub
from example2 as i have no more need for it

regards

Tammy


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
Combining two Subs Petitboeuf Excel Discussion (Misc queries) 6 April 27th 06 03:42 PM
Private subs Flima Excel Programming 1 January 7th 05 10:05 PM
Stringing Subs Randal W. Hozeski Excel Programming 2 May 28th 04 04:05 PM
calling subs Mike Excel Programming 4 April 8th 04 08:22 PM
Recursive Subs? ExcelMonkey[_74_] Excel Programming 5 February 5th 04 02:54 AM


All times are GMT +1. The time now is 03:38 AM.

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

About Us

"It's about Microsoft Excel"