Conditional compile statements

Code can be included or excluded from an application or module at compile time by using conditional compile statements which evaluate conditional compile constants. This can be helpful to exclude "developer only" features from a compiled application, for example.

Conditional compile constants can be declared explicitly in a module using #Const or can be set in the Project Properties -> Make tab -> Conditional Compilation Argument. These constants must be Boolean. Multiple constants should be are colon delimited (e.g. DEVEL_OPTIONS = -1 : ADMIN_OPTIONS = 0). If constants are set in the Project Properties, they do not have to be declared in the code.

Conditional compile statements are enclosed in #If... Then/#Else/#End If directives.

Example:

#If DEVEL_OPTIONS Then
     ' set DEVEL_OPTIONS = False to ignore this section on compile

     MsgBox "You've compiled with developer code."

#End If

More information can be found in this article.


Author: ASAK
Created: Nov 14 2005 (last modified Nov 28 2005)
Categories: Visual Basic
TechByte #82

Warning: By visiting this site and/or by using any information contained herein, you agree to the Techbytes.ca terms of use.



Add a comment about this TechByte

If you wish to add a comment regarding this TechByte, please use the form below. Please note that by submitting comments using this form you are allowing all of the information submitted to be visible on this website. Any comments submitted using this form will only be shown on the website if they are approved by the administrators of this site. IF APPROVED, COMMENTS MAY TAKE SEVERAL DAYS TO BE POSTED.

Posted By: (Optional)

Comments:


Other TechBytes: