#If…Then…#Else Directive available in next release of RAD Basic

The #If…Then…#Else directive in Visual Basic 6 is a powerful tool for conditional compilation. It allows developers to include or exclude blocks of code during the compilation process, based on specified conditions. This feature is particularly useful when dealing with multiple versions of a program, platform-specific code, or when incorporating features for debugging and testing purposes.

The syntax of the #If…Then…#Else directive is straightforward:

#If condition Then
   ‘ Code to include if the condition is true
#Else
   ‘ Code to include if the condition is false
#End If

It could be used in different uses cases.

Conditional Compilation

The primary purpose of #If…Then…#Else is to conditionally compile  code based on specific criteria. This could include checking the version of the operating system, the presence of certain components, or any  other condition that the developer deems necessary.

#If Win64 Then
   ‘ Code specific to 64-bit Windows
#Else
   ‘ Code for other platforms
#End If

Debugging and Testing

Developers often use conditional compilation for debugging and testing  purposes. By including or excluding debugging statements during  compilation, developers can easily switch between debug and release  versions of their code.

#If DEBUG_MODE Then
   ‘ Debugging statements
#Else
   ‘ Release version without debugging statements
#End If

Versioning

Managing code across different versions of a software product can be  challenging. The #If…Then…#Else directive allows developers to  include version-specific code or adapt code to changes in dependencies.

#If Win64 Then
   ‘ Code specific to 64-bit Windows
#Else
   ‘ Code for other platforms
#End If

RADBASIC compiler constant

In VB6/RAD Basic if a constant macro is not defined, it is evaluated as zero/false, so compilation never fails.

RAD Basic introduce a new compiler constant: RADBASIC. This constant is evaluated as false when compiling in Visual Basic 6 IDE, and evaluated as true in RAD Basic IDE.