View Single Post
  #7   Report Post  
Posted to microsoft.public.excel.programming
dreamz[_15_] dreamz[_15_] is offline
external usenet poster
 
Posts: 1
Default how to call subprocedure from within procedure?


Leith Ross Wrote:
Hello dreamz,

I looks like the variables in calculate are most likely going out of
scope, since you say it works with one call, but the other. If you are
not familiar the concept of scope and variable lifetimes, I'll explain
it briefly.

Scope has to do with the visibility (referencing) of a variable within
the program. A variable declared within a Sub or Function procedure for
a UserForm can only be seen by that procedure. If you want another Sub
or Function to be able to see (reference) that variable, you can do 2
things. One is to pass the variable to the other procedure, or make the
variable Public. To make the variable Public, available to all Subs and
Functions on the UserForm, you must place in the Declarations Section
of the User Form. Unlike local variables, the ones available only to
the Sub or Function itself, Public variables won't be re-initialized
when called again. So, you have to do that yourself. With a lot of
variables this can quickly become a programming nightmare.

A better option would be to place Calculate in a Project Module. This
will then broaden the scope to where any Sub or Function on a UserForm
or not can use it it. You will have to pass Calulate the variable
values chTr, chDep, chHum to it.

Sincerely,
Leith Ross

i tried putting calculate into a different module, but then it stopped
working completely (probably because i didn't change anything).

but i think you may be onto something. chTr, chDep, etc. are titles for
my checkboxes. when i say later:


Code:
--------------------
If chTr Then
--------------------


i mean, if chTr is checked, then do this.

do i need to declare these? how would i go about doing this?


--
dreamz
------------------------------------------------------------------------
dreamz's Profile: http://www.excelforum.com/member.php...o&userid=26462
View this thread: http://www.excelforum.com/showthread...hreadid=480621