Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 107
Default Enduring Variables

I frequently need to use variables in a program €“ could be words or numbers €“
which are available for as long as the programme is running.
The programme may contain several modules some or all of which may be called
during execution.
To achieve this, I define a named range and store the variable value in it.
This is tedious. I believe I can define an enduring variable as something like
"Public MyVariable", but have had no success.
If Public is the right approach,
How is it written?
Where do I put that declaration?
Can it go in "This Workbook" or must it go in a module?
If I use "Public" do all my modules have to be "Sub Public" ?
Some enlightenment would be much appreciated.
--
donwb
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Enduring Variables

Don,

It must go in a standard code module, and it should be declared before any
subs or functions in that module.

Do not put it in ThisWorkbook, else you will need to use
Thisworkbook.MyVariable.

It has no bearing on the declaration of the subs, so they can be public or
private depending on their usage.

--

HTH

RP
(remove nothere from the email address if mailing direct)


"donbowyer" wrote in message
...
I frequently need to use variables in a program - could be words or

numbers -
which are available for as long as the programme is running.
The programme may contain several modules some or all of which may be

called
during execution.
To achieve this, I define a named range and store the variable value in

it.
This is tedious. I believe I can define an enduring variable as something

like
"Public MyVariable", but have had no success.
If Public is the right approach,
How is it written?
Where do I put that declaration?
Can it go in "This Workbook" or must it go in a module?
If I use "Public" do all my modules have to be "Sub Public" ?
Some enlightenment would be much appreciated.
--
donwb



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 692
Default Enduring Variables

Bob,

I usually create a module for all my public variables,
and include comments to describe them.

But one thing I am not sure of - do Public variables hold there
value even when the code ends?

And if so - what is the best way to reset them to 0, or Nothing.

--
steveB

Remove "AYN" from email to respond
"Bob Phillips" wrote in message
...
Don,

It must go in a standard code module, and it should be declared before any
subs or functions in that module.

Do not put it in ThisWorkbook, else you will need to use
Thisworkbook.MyVariable.

It has no bearing on the declaration of the subs, so they can be public or
private depending on their usage.

--

HTH

RP
(remove nothere from the email address if mailing direct)


"donbowyer" wrote in message
...
I frequently need to use variables in a program - could be words or

numbers -
which are available for as long as the programme is running.
The programme may contain several modules some or all of which may be

called
during execution.
To achieve this, I define a named range and store the variable value in

it.
This is tedious. I believe I can define an enduring variable as something

like
"Public MyVariable", but have had no success.
If Public is the right approach,
How is it written?
Where do I put that declaration?
Can it go in "This Workbook" or must it go in a module?
If I use "Public" do all my modules have to be "Sub Public" ?
Some enlightenment would be much appreciated.
--
donwb





  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Enduring Variables

Hi Steve,

I do the same for bigger projects. I store all my Public variables and
Public constants in there.

As for holding their value, yes they will maintain throughout the Excel
session. To re-initialise them, you will need specific code to do so. Where
you run that code will be a design decision, but it may be well worth having
a button to do so. Personally, even with Public variables I can't think of
many situations where I use that to hold persistent data, it tends to be to
have a value that will be used in many macros, across modules, but will
always be initialised within one of them.

--

HTH

RP
(remove nothere from the email address if mailing direct)


"STEVE BELL" wrote in message
news:MDuIe.43397$MW5.20588@trnddc08...
Bob,

I usually create a module for all my public variables,
and include comments to describe them.

But one thing I am not sure of - do Public variables hold there
value even when the code ends?

And if so - what is the best way to reset them to 0, or Nothing.

--
steveB

Remove "AYN" from email to respond
"Bob Phillips" wrote in message
...
Don,

It must go in a standard code module, and it should be declared before

any
subs or functions in that module.

Do not put it in ThisWorkbook, else you will need to use
Thisworkbook.MyVariable.

It has no bearing on the declaration of the subs, so they can be public

or
private depending on their usage.

--

HTH

RP
(remove nothere from the email address if mailing direct)


"donbowyer" wrote in message
...
I frequently need to use variables in a program - could be words or

numbers -
which are available for as long as the programme is running.
The programme may contain several modules some or all of which may be

called
during execution.
To achieve this, I define a named range and store the variable value in

it.
This is tedious. I believe I can define an enduring variable as

something
like
"Public MyVariable", but have had no success.
If Public is the right approach,
How is it written?
Where do I put that declaration?
Can it go in "This Workbook" or must it go in a module?
If I use "Public" do all my modules have to be "Sub Public" ?
Some enlightenment would be much appreciated.
--
donwb







  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 692
Default Enduring Variables

Bob,

Thanks for confirming what I suspected. And you are right - in most
situations the individual modules shouldn't be sensitive to any existing
value held by the variable. If you suspect that it will, then initialize
the value in the code....

--
steveB

Remove "AYN" from email to respond
"Bob Phillips" wrote in message
...
Hi Steve,

I do the same for bigger projects. I store all my Public variables and
Public constants in there.

As for holding their value, yes they will maintain throughout the Excel
session. To re-initialise them, you will need specific code to do so.
Where
you run that code will be a design decision, but it may be well worth
having
a button to do so. Personally, even with Public variables I can't think of
many situations where I use that to hold persistent data, it tends to be
to
have a value that will be used in many macros, across modules, but will
always be initialised within one of them.

--

HTH

RP
(remove nothere from the email address if mailing direct)


"STEVE BELL" wrote in message
news:MDuIe.43397$MW5.20588@trnddc08...
Bob,

I usually create a module for all my public variables,
and include comments to describe them.

But one thing I am not sure of - do Public variables hold there
value even when the code ends?

And if so - what is the best way to reset them to 0, or Nothing.

--
steveB

Remove "AYN" from email to respond
"Bob Phillips" wrote in message
...
Don,

It must go in a standard code module, and it should be declared before

any
subs or functions in that module.

Do not put it in ThisWorkbook, else you will need to use
Thisworkbook.MyVariable.

It has no bearing on the declaration of the subs, so they can be public

or
private depending on their usage.

--

HTH

RP
(remove nothere from the email address if mailing direct)


"donbowyer" wrote in message
...
I frequently need to use variables in a program - could be words or
numbers -
which are available for as long as the programme is running.
The programme may contain several modules some or all of which may be
called
during execution.
To achieve this, I define a named range and store the variable value
in
it.
This is tedious. I believe I can define an enduring variable as

something
like
"Public MyVariable", but have had no success.
If Public is the right approach,
How is it written?
Where do I put that declaration?
Can it go in "This Workbook" or must it go in a module?
If I use "Public" do all my modules have to be "Sub Public" ?
Some enlightenment would be much appreciated.
--
donwb










  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 107
Default Enduring Variables

Bob
Many thanks. It worked fine
--
donwb


"Bob Phillips" wrote:

Don,

It must go in a standard code module, and it should be declared before any
subs or functions in that module.

Do not put it in ThisWorkbook, else you will need to use
Thisworkbook.MyVariable.

It has no bearing on the declaration of the subs, so they can be public or
private depending on their usage.

--

HTH

RP
(remove nothere from the email address if mailing direct)


"donbowyer" wrote in message
...
I frequently need to use variables in a program - could be words or

numbers -
which are available for as long as the programme is running.
The programme may contain several modules some or all of which may be

called
during execution.
To achieve this, I define a named range and store the variable value in

it.
This is tedious. I believe I can define an enduring variable as something

like
"Public MyVariable", but have had no success.
If Public is the right approach,
How is it written?
Where do I put that declaration?
Can it go in "This Workbook" or must it go in a module?
If I use "Public" do all my modules have to be "Sub Public" ?
Some enlightenment would be much appreciated.
--
donwb




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
Not at all clear on use of variables and/or object variables JMay-Rke Excel Discussion (Misc queries) 11 July 4th 08 06:36 PM
Variables Phil Excel Programming 1 April 15th 05 04:39 PM
Variables Chip Pearson Excel Programming 0 July 9th 04 04:22 PM
Variables No Name Excel Programming 2 July 9th 04 05:37 AM
DIm Variables Todd Huttenstine Excel Programming 4 April 26th 04 04:37 PM


All times are GMT +1. The time now is 10:21 AM.

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"