Anytime Help Center

Contact Us

If you still have questions or prefer to get help directly from an agent, please submit a request.
We’ll get back to you as soon as possible.

Please fill out the contact form below and we will reply as soon as possible.

  • Support
  • Guest
  • Log In
English (US)
US English (US)
DE German
CN Chinese
MX Spanish (Mexico)
Chinese (Simplified)
  • AKG
    Microphones Wireless Integrated Systems Automatic Mixers Headphones Discontinued Products (AKG) General AKG Inquiries Certifications (AKG)
  • AMX
    Networked A/V Distribution (AVoIP) Traditional A/V Distribution Video Signal Processing Architectural Connectivity User Interfaces Control Processing Power (AMX) Programming (AMX) Software (AMX) Discontinued Products (AMX) General AMX Inquiries Certifications (AMX)
  • BSS
    Soundweb™ Omni Soundweb™ London Soundweb™ Contrio™ Software (BSS) Discontinued Products (BSS) General BSS Inquiries Certifications (BSS)
  • Crown
    CDi DriveCore Series CDi Series Commercial Series ComTech Series DCi DriveCore Series I-Tech HD Series XLC series XLi Series XLS DriveCore 2 Series XTi 2 Series Discontinued Products (Crown) Software (Crown) General Crown Inquiries Certifications (Crown)
  • dbx
    CX Series 500 Series DriveRack Personal Monitor Control ZonePRO Zone Controllers FeedBack Suppression Microphone Preamps Dynamics Processors Crossovers Equalizers Software (dbx) Discontinued Products (dbx) General dbx Inquiries Certifications (dbx)
  • Flux::
    Immersive Processing Analysis Subscriptions
  • JBL
    Cinema Sound Installed Live Portable Tour Sound Recording & Broadcast Software (JBL) Discontinued Products (JBL) Video Manual Series (JBL) General JBL Inquiries Certifications (JBL)
  • Lexicon
    Plugins Effects Processors Cinema Discontinued Products (Lexicon) Video Manual Series (Lexicon) General Lexicon Inquiries Certifications (Lexicon)
  • Martin
    Atomic ELP ERA Exterior MAC P3 VC VDO Tools Discontinued Products (Martin) General Martin Inquiries Certifications (Martin)
  • Soundcraft
    Digital Analog Connected Analog Only Discontinued Products (Soundcraft) Video Manual Series (Soundcraft) General Soundcraft Inquiries Certifications (Soundcraft)
  • General HARMAN Inquiries
    Dante
+ More
  • Home
  • AMX
  • Programming (AMX)
  • Programming

How to use #IF_DEFINED to set pre-compile conditions

Written by Gary Brindley

Updated at January 12th, 2026

Table of Contents

Question: Answer:

Question:

How do I use #IF_DEFINED to set pre-compile conditions?

Answer:

The attached code demonstrates how to use #if_defined to determine something to do, like load the appropriate module based on which room you're loading the code. In this demonstration, the code will load a module based on which room has been defined. This is useful if you have multiple rooms that all use the same code but have a different device, like one room has a Samsung TV with a different model number from another room. Just comment out / in the correct room variable and the code will load the correct module.

This can be used for many things. The modules are just an example. 

Download Code

PROGRAM_NAME='How to use #IF_DEFINED to set pre-compile conditions'
(***********************************************************)
(***********************************************************)
(*  FILE_LAST_MODIFIED_ON: 04/05/2006  AT: 09:00:25        *)
(***********************************************************)
(***********************************************************)
(*  FILE REVISION: Rev 0                                   *)
(*  REVISION DATE: 12/09/2024  AT: 13:07:11                *)
(*                                                         *)
(*  COMMENTS:                                              *)
(*  This code demonstrates how to use #if_defined to       *)
(*  determine something to do, like load the appropriate   *)
(*  module based on which room you're loading the code   	 *)
(*                                                         *)
(***********************************************************)
(* System Type : NetLinx                                   *)
(***********************************************************)
(* REV HISTORY:                                            *)
(***********************************************************)
(*
    $History: $
*)
(***********************************************************)
(*          DEVICE NUMBER DEFINITIONS GO BELOW             *)
(***********************************************************)
DEFINE_DEVICE


dvMaster		 			= 0:1:0			// MASTER
dvTP 							= 10001:1:0	// TOUCH PANEL

dvVIRTUALKEYPAD 	=	0:2:0
vdvVIRTUALKEYPAD 	= 41001:1:0

dvNXB_KNX 				=	5001:1:0	// NXB-KNX DEVICE
vdvGateway 				=	41002:1:0	// VIRTUAL IP DEVICE 

(***********************************************************)
(*               CONSTANT DEFINITIONS GO BELOW             *)
(***********************************************************)
DEFINE_CONSTANT

(***********************************************************)
(*              DATA TYPE DEFINITIONS GO BELOW             *)
(***********************************************************)
DEFINE_TYPE

(***********************************************************)
(*               VARIABLE DEFINITIONS GO BELOW             *)
(***********************************************************)
DEFINE_VARIABLE

#WARN 'THIS IS WHERE YOU WOULD COMMENT OR UNCOMMENT A DEFINITION TO TRIGGER THE #IF_DEFINED BEFORE LOADING THE CODE INTO ALL THE ROOMS'
VOLATILE INTEGER nDiningRoom
//VOLATILE INTEGER nBallRoom


(***********************************************************)
(*               LATCHING DEFINITIONS GO BELOW             *)
(***********************************************************)
DEFINE_LATCHING

(***********************************************************)
(*       MUTUALLY EXCLUSIVE DEFINITIONS GO BELOW           *)
(***********************************************************)
DEFINE_MUTUALLY_EXCLUSIVE

(***********************************************************)
(*        SUBROUTINE/FUNCTION DEFINITIONS GO BELOW         *)
(***********************************************************)
(* EXAMPLE: DEFINE_FUNCTION <RETURN_TYPE> <NAME> (<PARAMETERS>) *)
(* EXAMPLE: DEFINE_CALL '<NAME>' (<PARAMETERS>) *)

(***********************************************************)
(*                STARTUP CODE GOES BELOW                  *)
(***********************************************************)
DEFINE_START

#WARN 'BASED ON WHICH VARIABLE IS DEFINED (WHICH ROOM LOADING CODE IN) THE CORRECT MODULE WILL LOAD'
#IF_DEFINED nBallRoom
DEFINE_MODULE 'AMX_VirtualKeypad_dr1_0_0' VKP(vdvVIRTUALKEYPAD,dvVIRTUALKEYPAD)
#END_IF

#IF_DEFINED nDiningRoom
DEFINE_MODULE 'AMX_KNXModulesGateway_dr1_0_0' KNXGATEWAY(vdvGateway,dvNXB_KNX)
// THERE CAN BE MULTIPLE LINES HERE. tHE #IF_DEFINED RUNS UNTIL THE #END_IF
#END_IF

(***********************************************************)
(*                THE EVENTS GO BELOW                      *)
(***********************************************************)
DEFINE_EVENT

(*****************************************************************)
(*                                                               *)
(*                      !!!! WARNING !!!!                        *)
(*                                                               *)
(* Due to differences in the underlying architecture of the      *)
(* X-Series masters, changing variables in the DEFINE_PROGRAM    *)
(* section of code can negatively impact program performance.    *)
(*                                                               *)
(* See  Differences in DEFINE_PROGRAM Program Execution  section *)
(* of the NX-Series Controllers WebConsole & Programming Guide   *)
(* for additional and alternate coding methodologies.            *)
(*****************************************************************)

DEFINE_PROGRAM

(*****************************************************************)
(*                       END OF PROGRAM                          *)
(*                                                               *)
(*         !!!  DO NOT PUT ANY CODE BELOW THIS COMMENT  !!!      *)
(*                                                               *)
(*****************************************************************)


Related Videos

Was this article helpful?

Yes
No
Give feedback about this article

Table of Contents

Question: Answer:

Related Articles

  • AMX Subroutine Name Length
  • How To Send DGX Shell Commands From NetLinx Code
  • Using a NetLinx Master to Monitoring a System
  • Using an Active Bargraph to Control Levels by Touching the Bargraph
  • Netlinx Controller Locks Up Connecting to Devices via IP

Related Articles

  • AMX Subroutine Name Length
  • How To Send DGX Shell Commands From NetLinx Code
  • Using a NetLinx Master to Monitoring a System
  • Using an Active Bargraph to Control Levels by Touching the Bargraph
  • Netlinx Controller Locks Up Connecting to Devices via IP
Copyright © HARMAN Professional. All rights reserved. Privacy Policy | Terms of Use
Expand