Please enable JavaScript to view this site.

 

Navigation: Macros > The Macros Editor > Writing Macros

Writing Blocks of Code

Scroll Prev Up Next More

In macros, there are many structures which involve blocks of code framed by delimiting keywords at the beginning and end of the block. One example is the if-else-endif branching structure (other examples are the while, for and switch structures).

if
   // do something
else
   // do something else
endif

There are 2 potential sources of errors stemming from blocks of code :

 

Misalignment of the keywords that mark the start and finish of a block can lead to logical bugs in your code (ie. the macro does compile but does not produce the expected results).

Missing keywords at the end of the macro will generate a compilation error.

 

To prevent both types of errors, we suggest that you always write the entire skeleton of a block before writing the code inside. For example, in the case of an if-else-endif block you would follow the sequence:

 

 

 

In the above sequence, all you need to do is type "if" then press RETURN twice then write "else" then press RETURN twice then write "endif". The automated indentation of the macros editor ensures that each of the keywords is indented properly so that your code reads as it is processed.

 


Topic 172160, last updated on 18-Apr-2020