Constant and Compile

M

Marty

Hi,

In VB.NET, what happen to constants when compiling? Are they copied at
every place they are needed? Or the application has to refer to
constants address each time it need it at run time?

Thanks
Marty
 
S

scorpion53061

You can set conditional compilation constants in one of three ways:

In the Property Pages dialog box
At the command line when using the command-line compiler
In your code
Conditional compilation constants have a special scope and cannot be
accessed from standard code. The scope of a conditional compilation
constant is dependant on the way it is set. The following table lists
the scope of constants declared using each of the three ways mentioned
above.

How Constant is Set Scope of Constant
Property Pages dialog box Public to all files in the project
Command line Public to all files passed to the command-line compiler
#Const statement in code Private to the file in which it is declared

To set constants in the Property Pages dialog box

Before creating your executable file, set constants in the Property
Pages dialog box by following the steps provided in Setting Visual Basic
Project Properties.
To set constants at the command line

Use the /d switch to enter conditional compilation constants, as in the
following example:
vbc MyProj.vb /d:conFrenchVersion=-1:conANSI=0
No space is required between the /d switch and the first constant.

Command-line declarations override declarations entered in the Property
Pages dialog box, but do not erase them. Arguments set in Property Pages
remain in effect for subsequent compilations.

When writing constants in the code itself, there are no strict rules as
to their placement, since their scope is the entire module in which they
are declared.

To set constants in your code

Place the constants in the declaration block of the module in which they
are used. This helps keep your code organized and easier to read.
 
I

Imran Koradia

I believe the compiler replaces all instances of the constant with its
actual value when compiling.

Imran.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top