#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 905
Default Const?

If I declare "Const foo as Integer = 123", does that allocate storage?

Or does that create a compile-time constant that replaces "foo" wherever it
is used in executable statements?

If the latter, is "Const foo as Integer = 123*456" and "x = foo" more
efficient than "x = 123*456"? In particular, does the compiler treat "x =
foo" as "x = 56088"?

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,565
Default Const?

The answer to the first question is yes.



"Joe User" <joeu2004 wrote in message
...
If I declare "Const foo as Integer = 123", does that allocate storage?

Or does that create a compile-time constant that replaces "foo" wherever
it is used in executable statements?

If the latter, is "Const foo as Integer = 123*456" and "x = foo" more
efficient than "x = 123*456"? In particular, does the compiler treat "x =
foo" as "x = 56088"?



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Const?


I believe that the compiler evaluates any constants and replaces them
with their values before any code execution takes place. This is why
you can assign to constants values that can be evaluated
arithmetically with actual constants (Const ABC = 1234 * 10) or other,
previously declared constants (Const ABC = DEF * 10, where DEF is a
previously declared constant).

As far as efficiency at run time, a simple constant makes no
difference at all and an arithmetic const is only marginally
(microseconds) better than having the arithmetic in the actual run
time code.

Cordially,
Chip Pearson
Microsoft MVP 1998 - 2010
Pearson Software Consulting, LLC
www.cpearson.com
[email on web site]


On Sat, 12 Dec 2009 16:58:08 -0800, "Joe User" <joeu2004 wrote:

If I declare "Const foo as Integer = 123", does that allocate storage?

Or does that create a compile-time constant that replaces "foo" wherever it
is used in executable statements?

If the latter, is "Const foo as Integer = 123*456" and "x = foo" more
efficient than "x = 123*456"? In particular, does the compiler treat "x =
foo" as "x = 56088"?

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 905
Default Const?

"Chip Pearson" wrote:
I believe that the compiler evaluates any constants
and replaces them with their values before any code
execution takes place. This is why you can assign to
constants values that can be evaluated arithmetically
with [...] previously declared constants (Const ABC = DEF * 10


Good point! Shoulda thought of that myself. Thanks.


----- original message -----

"Chip Pearson" wrote in message
...

I believe that the compiler evaluates any constants and replaces them
with their values before any code execution takes place. This is why
you can assign to constants values that can be evaluated
arithmetically with actual constants (Const ABC = 1234 * 10) or other,
previously declared constants (Const ABC = DEF * 10, where DEF is a
previously declared constant).

As far as efficiency at run time, a simple constant makes no
difference at all and an arithmetic const is only marginally
(microseconds) better than having the arithmetic in the actual run
time code.

Cordially,
Chip Pearson
Microsoft MVP 1998 - 2010
Pearson Software Consulting, LLC
www.cpearson.com
[email on web site]


On Sat, 12 Dec 2009 16:58:08 -0800, "Joe User" <joeu2004 wrote:

If I declare "Const foo as Integer = 123", does that allocate storage?

Or does that create a compile-time constant that replaces "foo" wherever
it
is used in executable statements?

If the latter, is "Const foo as Integer = 123*456" and "x = foo" more
efficient than "x = 123*456"? In particular, does the compiler treat "x =
foo" as "x = 56088"?


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
Const and VBA values sgl Excel Programming 4 May 19th 08 07:39 PM
Public Const & RowSource Karen53 Excel Programming 4 November 30th 07 08:13 PM
Const Array Sören_Marodören Excel Programming 3 January 25th 07 01:09 PM
Not recognizing a Const Dan T[_3_] Excel Programming 7 July 18th 04 12:45 AM
crash changing const to public const BrianB Excel Programming 0 August 4th 03 10:13 AM


All times are GMT +1. The time now is 08:19 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"