Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Defining public/global variables in more than one place

Using Excel 2003 (hopefully will persuade my company to allow us to upgrade our excel reports to 2010 at some point!)

I am trying to standardise the code in our executables to make coding/maintenance easier and have come up with the following idea:

1. Our Excel reports have a simple Auto_Open module that will be the first piece of code in every report we have and this has 1 public variable plus one actual command to call another module sub called Main_Processing. This other module will contain the report relevant logic.

2. This public variable defined in the Auto_Open module is a string defining the environment the code runs in such as Test, Development and thus can be altered simply for each environment. Lower level code uses this to pick up data files from the correct place for that environment.

3. This is the part my question relates to. Can the Main_Processing module also have public variables that are used in lower level sub routines and functions? So far, I have only defined global variables in one place at the top level, so the question is really about scope of lower level variables.

Cheers
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Defining public/global variables in more than one place

PLEASE IGNORE

Did what I should have done before posting and tried it out.

All works fine when defined as Public at each level
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 84
Default Defining public/global variables in more than one place

I don't follow what you mean by "lower level sub routines", however are
variables can maintain scope (even while code is not running) at three
levels:

Global, visible throughout the project, declare at the top of a normal
module:
Public gsMyString As String

Module, visible throughout the module only, declare at the top of the
module:
Private msMyString as String

Procedure, visible only within a single routine, declare within the routine:
Static sMyString As String

Use of the End statement or anything while debugging that breaks and
prevents completion of code will reset all variables, something to keep in
mind

It's a matter of style but avoid use of such variables as "a convenience".
Rule of thumb, if the variable is not required to be stored between
subsequently running the code, pass variable as required between routines.

Regards,
Peter T


"stainless" wrote in message
...
Using Excel 2003 (hopefully will persuade my company to allow us to upgrade
our excel reports to 2010 at some point!)

I am trying to standardise the code in our executables to make
coding/maintenance easier and have come up with the following idea:

1. Our Excel reports have a simple Auto_Open module that will be the first
piece of code in every report we have and this has 1 public variable plus
one actual command to call another module sub called Main_Processing. This
other module will contain the report relevant logic.

2. This public variable defined in the Auto_Open module is a string defining
the environment the code runs in such as Test, Development and thus can be
altered simply for each environment. Lower level code uses this to pick up
data files from the correct place for that environment.

3. This is the part my question relates to. Can the Main_Processing module
also have public variables that are used in lower level sub routines and
functions? So far, I have only defined global variables in one place at the
top level, so the question is really about scope of lower level variables.

Cheers

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
Global/Public/Universal variables Matthew Dyer Excel Programming 8 September 17th 11 08:29 PM
Global/Public Fox via OfficeKB.com Excel Programming 2 May 26th 06 08:44 PM
Global variables - where do you place them? CRayF Excel Programming 16 September 28th 05 01:14 AM
problems defining a global variable filo666 Excel Programming 2 August 17th 05 10:26 PM
Public vs Global quartz[_2_] Excel Programming 2 February 9th 05 06:20 PM


All times are GMT +1. The time now is 09:49 PM.

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"