Pre-proccessor / Compiler Constants

  • Thread starter Thread starter David B
  • Start date Start date
D

David B

Hi,

Please could somebody tell how to define a compiler constant.

By this I mean define an Item in the configuration properties, called
"TestCode"
To do this choose configuration properties and then from "Active Solution
Configuration" dropdown select "New" and define the new constant -- ie
"TestCode"

Now "TestCode" appears in the configuration dropdown on the standard toolbar
along with "Debug" and "Release"

Now if I define the following code (see end of email) with "TestCode"
selected from the dropdown I would have expected the code inside the "#if
TESTCODE" block to compile -- except it does not.

I have seen this work before in C# where if somebody picks "testcode" from
the dropdown then the code in the "#else" is greyed out and vice versa.
My problem is that I can't get this to work and I feel that I must be
missing something.

If anybody could steer me in the correct direction then I would appreciate
it.

cheers

martin



//C#
#if TESTCODE
{

}
#else
{

}
#endif


'VB
#If testcode Then
MessageBox.Show("TestCode Compile")
#Else
MessageBox.Show("NOT a TestCode Compile")
#End If
 
David,
You've only defined the configuration, you still need to define the compiler
constant itself.

Use the Project Property Pages, select your new Configuration in the
Configuration drop down.

Select 'Configuration Properties - Build' in the tree. Add your constant
under 'Conditional Compilation Constants' for C# & 'Custom constants' for
VB.NET.

Hope this helps
Jay
 
Back
Top