<< Prev        Next >>

ID : 112

#Define

Function

To define macro.

Syntax

#Define macro name code

Guaranteed entry

Macro name
Designate a macro name. In case of a functional macro, enclose the argument in brackets "()."
Code
Designate a code to replace the macro name.

Description

Macro name in the program is replaced with code. In case of a functional macro, it is replaced along with its argument.

A space character must be placed between a macro name and a code.

Macro name needs to be naming conventioned based on naming convention.

A space character must not be placed between a macro name or a code and the brackets "()" enclosing them.

Macro name must be 64 or less characters.

Related Terms

Preprocessor

Attention

Text within the string enclosed in double quotation marks ("") cannot be replaced.

Recursive replacement is not performed.

#Define AA 5
#Define BB(x) 100*x + sin(x)
PrintDbg BB(AA) 'Not compiled completely.

bb(aa) in the above example is converted to 100*aa + sin(aa) in the preprocessor process as code generation, not to 100*5 + sin(5).

#Define AA BB
#Define BB 100
PrintDbg AA 'Not compiled completely.

In the above example also, PrintDbg AA is converted to PrintDbg BB as code generation.

Example

'!TITLE "Macro Definition"
' Display a string designated in the macro name and calculation result
Sub Sample_Define
' Assign "Desno Corporation" to a macro called NAME
#Define NAME "Denso Corporation"
' Declare mAREA(radius) as a macro
#Define mAREA( radius ) PI * Pow( radius, 2 )
  Dim aaa As String
  Dim bbb As Double
  ' Assign "Denso Corporation" to aaa
  aaa = NAME
  ' Assign calculation result of PI * (square of 10) to bbb
  bbb = mAREA( 10 )
  ' Display "Denso Corporation" on the message output window
  PrintDbg aaa
  ' Display calculation result on the message output window
  PrintDbg bbb
End Sub

ID : 112

<< Prev        Next >>