<< Prev        Next >>

ID : 116

#Ifdef ... #Endif

Function

To determine whether the designated macro is defined and select a source code to compile.

Syntax

#Ifdef macro name
	Code 1
#Elif Defined(macro name)
	Code 2
#Else
	Code 3
#Endif

Guaranteed entry

Macro name
Designate a macro name.
Code n
Designate a source code.

Description

It is determined whether the designated macro is defined and a source code to compile is selected.

If the macro name is defined, code 1, but not code 2 and code 3, is compiled.

If the macro name is not defined, the condition is judged and either of code 2 or code 3 is compiled.

The same as #If Defined(macro name) ...

Related Terms

Attention

When the embedded macro is used as a macro name, the evaluation result is always TRUE, this makes the conditional branch ineffective.
For example, in the code below, <Code1> is always applied regardless of the robot type, and <Code2> is never applied.

#Ifdef __SCARA_ROBOT__
... <Code1>
#Else
... <Code2>
#EndIf
To execute this conditional branch appropriately, you need to use #If syntax and write as follows.
#If __SCARA_ROBOT__
  ... <Code1>
#Else
  ... <Code2>
#EndIf

Example

'!TITLE "Condition Compile"
' Judge whether a macro is defined and add a value to aaa

#Define TEST2 20

Sub Sample_IfdefEndif

  Dim aaa As Integer

  aaa = 10

' If a macro name TEST is defined
#Ifdef TEST

  aaa = aaa + 10

  ' Display a value of aaa on the message output window
  PrintDbg "aaa = " & aaa

' If a macro name TEST2 is defined
#Elif Defined(TEST2)

  aaa = aaa + 20

  ' Display a value of aaa on the message output window
  PrintDbg "aaa = " & aaa

' If both of a macro name TEST and TEST2 are not defined
#Else

  aaa = aaa + 30

  ' Display a value of aaa on the message output window
  PrintDbg "aaa = " & aaa

#Endif

End Sub

ID : 116

<< Prev        Next >>