PC Review


Reply
Thread Tools Rate Thread

Declaring Variables

 
 
BlairH
Guest
Posts: n/a
 
      4th Jun 2010
I'm either horribly confused, or old age is taking its toll. But there seems
to be too many options for declaring variables and I;m having trouble
figuring out the best way for declaring variables.

Tell me if I have it straight:

variables declared at the top of a module are shared within all procedures
in the module, decalred within a procedure/function are available to only
that procedure/function

variables declared Public are available to all modules
- in this workbook only or all workbooks?
- so these should be declared at the top of a module?

variables declared Static retain their values between procedure/function calls
- declare in a procedure/function

variables do not retain their values once hte code stops and control returns
to the user, so if you want to retain values you need to stor ethem in a cell
in the spreadsheet

Sound right?

Thanks!
 
Reply With Quote
 
 
 
 
Jackpot
Guest
Posts: n/a
 
      4th Jun 2010
Does these articles help.

http://www.ozgrid.com/VBA/variable-scope-lifetime.htm
http://www.java2s.com/Code/VBA-Excel...sics/Const.htm

"BlairH" wrote:

> I'm either horribly confused, or old age is taking its toll. But there seems
> to be too many options for declaring variables and I;m having trouble
> figuring out the best way for declaring variables.
>
> Tell me if I have it straight:
>
> variables declared at the top of a module are shared within all procedures
> in the module, decalred within a procedure/function are available to only
> that procedure/function
>
> variables declared Public are available to all modules
> - in this workbook only or all workbooks?
> - so these should be declared at the top of a module?
>
> variables declared Static retain their values between procedure/function calls
> - declare in a procedure/function
>
> variables do not retain their values once hte code stops and control returns
> to the user, so if you want to retain values you need to stor ethem in a cell
> in the spreadsheet
>
> Sound right?
>
> Thanks!

 
Reply With Quote
 
Jackpot
Guest
Posts: n/a
 
      4th Jun 2010
I notice the specific question marks only now..Answers within brackets


- in this workbook only or all workbooks?
(In this workbook)

- so these should be declared at the top of a module?
(Yes)

variables declared Static retain their values between procedure/function calls
- declare in a procedure/function (Yes)


-variables do not retain their values once hte code stops and control
returns to the user, so if you want to retain values you need to stor ethem
in a cell
in the spreadsheet Sound right?

(Variables declared on top will retain their values all through that
Application session OR until Excel application is closed (assuming they are
not initialised within code))

"Jackpot" wrote:

> Does these articles help.
>
> http://www.ozgrid.com/VBA/variable-scope-lifetime.htm
> http://www.java2s.com/Code/VBA-Excel...sics/Const.htm
>
> "BlairH" wrote:
>
> > I'm either horribly confused, or old age is taking its toll. But there seems
> > to be too many options for declaring variables and I;m having trouble
> > figuring out the best way for declaring variables.
> >
> > Tell me if I have it straight:
> >
> > variables declared at the top of a module are shared within all procedures
> > in the module, decalred within a procedure/function are available to only
> > that procedure/function
> >
> > variables declared Public are available to all modules
> > - in this workbook only or all workbooks?
> > - so these should be declared at the top of a module?
> >
> > variables declared Static retain their values between procedure/function calls
> > - declare in a procedure/function
> >
> > variables do not retain their values once hte code stops and control returns
> > to the user, so if you want to retain values you need to stor ethem in a cell
> > in the spreadsheet
> >
> > Sound right?
> >
> > Thanks!

 
Reply With Quote
 
BlairH
Guest
Posts: n/a
 
      4th Jun 2010
Those article sdo help. Thanks.

"Jackpot" wrote:

> Does these articles help.
>
> http://www.ozgrid.com/VBA/variable-scope-lifetime.htm
> http://www.java2s.com/Code/VBA-Excel...sics/Const.htm
>
> "BlairH" wrote:
>
> > I'm either horribly confused, or old age is taking its toll. But there seems
> > to be too many options for declaring variables and I;m having trouble
> > figuring out the best way for declaring variables.
> >
> > Tell me if I have it straight:
> >
> > variables declared at the top of a module are shared within all procedures
> > in the module, decalred within a procedure/function are available to only
> > that procedure/function
> >
> > variables declared Public are available to all modules
> > - in this workbook only or all workbooks?
> > - so these should be declared at the top of a module?
> >
> > variables declared Static retain their values between procedure/function calls
> > - declare in a procedure/function
> >
> > variables do not retain their values once hte code stops and control returns
> > to the user, so if you want to retain values you need to stor ethem in a cell
> > in the spreadsheet
> >
> > Sound right?
> >
> > Thanks!

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Declaring variables ericb Microsoft Access 9 23rd Feb 2010 05:26 PM
Declaring Variables Twice? Chad Microsoft Excel Programming 2 19th May 2009 11:48 PM
Re: DEclaring variables Pedro Microsoft Excel Programming 1 13th Nov 2003 05:02 PM
Declaring variables HHickey Microsoft Dot NET Framework 1 13th Nov 2003 04:39 PM
DEclaring variables Pedro Microsoft Excel Programming 2 13th Nov 2003 11:54 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:35 PM.