Using Conditional Compilation Arguments - June 2000

I have been using VB's conditional compilation arguments since they became available in version 4 [32-bit]. I have not seen much written about them. So I thought I'd discuss conditional compilation arguments as the tip-of-the-month.


I have primarily used conditional compilation arguments for two purposes:

1. To create different, but similar, applications while maintaining one code base.
2. To maintain one code base for different versions of the same application. 

The Demo Program

I created a demo program that shows how to create two applications using one code base. And how to support an earlier version of the application while working on a new version. There are four variations:

Application One Application Two

Specifying Conditional Compilation Arguments

I set conditional compilation arguments through the project properties dialog. Click on menu Project, Properties then click the 'Make' tab. For example:

In this example App1 is set true, App2 is set false and Version2 code will be generated. Arguments are separated by a colon. Zero indicates the argument is set to false. Any other value equates to true. It sure would be nice if the size of this box were increased. I have some applications with 10 or more arguments. For example: I set Beta to true while developing code and use that argument to modify text in the about box warning the user that a beta version of the product is being used.

2000/12/02 - The space allowed for entry of CCA's in the standard VB 6 dialog is very small. I found a way to increase the size of VB's dialog boxes. For more info on this subject, jump to the November 2000 tip-of-the-month 'Make VB's Dialog Boxes Larger'.

One and Only One Application

Typically while developing multiple applications from one code base only one application should be selected. I added code in the demo to make sure that only one application is selected. If not the following message is issued:

Too Many

Using Conditional Compilation Arguments In Code

See 'Using Conditional Compilation', '#If…Then…#Else Directive' and '#Const Statement in the VB documentation. Sample code:

#If App1 Then 'run application one
#ElseIf App2 Then 'run application two
#End If

The Demo Uses modConnectToWebSite

The demo program uses modConnectToWebSite.bas to display this page. For details on the use of that module click here.

Download VB Code

Click here to download the VB 6 Source Code [13k]. 

Previous Tip   Tip Index    Next Tip


Updated 2009/04/14