Omni Systems, Inc.

  

Mif2Go User's Guide, Version 55

  

Valid HTML 4.01!

 

Made with Mif2Go

28 Working with macros > 28.3 Using macro variables > 28.3.3 Incrementing and decrementing macro variables


28.3.3 Incrementing and decrementing macro variables

You can increment the value of a macro variable by 1 (one) like this:

<$$myvar++> (or just <$$myvar+>)

or decrement the value by 1 like this:

<$$myvar--> (or just <$$myvar->)

For example, to count Body paragraphs in a FrameMaker file for HTML output, incrementing the count before using it:

[HTMLParaStyles]

Body=CodeStart

[ParaStyleCodeStart]

Body=<!-- this is <$$bodynum++ as %0.3d> -->

[MacroVariables]

bodynum=bp000

These settings result in a comment like the following for each instance of a Body paragraph in the HTML output:

<!-- this is bp003 -->

Reserve enough digits

You must include enough placeholder digits in the starting value (in this example, bp000) to accommodate the range of values you expect in the file. If you do not, the number will roll over to zero after it reaches its maximum value: in this example bp999 would increment to bp000. If the value has no digits at all at the end, the last letter is incremented instead; so a starting value of aaa increments to aab, aac, ..., aaz, aba, ..., zzz, aaa. Case is retained for the incremented (or decremented) letter.

To increment the value after use, move the incrementing code after the reference:

[ParaStyleCodeStart]

Body=<!-- this is <$$bodynum> --><$$bodynum++>

Reset the starting value

Numbers restart for each FrameMaker file. If you require the numbers to be unique in your Mif2Go project, you must use an individual FMfilename.ini configuration file for each FrameMaker file in your document, and include in it a [MacroVariables] section with a starting value for that file.

Increment by assignment

You can use an assignment (see §28.3.2 Assigning values to macro variables) as another form of increment, as in the following:

<$$myvar = ($$myvar + 1)>

This form does not require reserving the maximum number of digits first.

Increment hexadecimal numbers

Incrementing and decrementing using ++ or -- notation does not work with values stored as hexadecimal numbers; for those you must use an assignment to increment or decrement:

<$$myhex = ($$myhex + 1)>

Display an increment

You can also display the value of an increment or decrement by adding as and a printf() format; for example:

<$$myvar++ as %d>

<$$myvar = ($$myvar + 1) as %0.4d>

See §28.6.3 Displaying expression results in output for information about display formats.

Increment indirectly

You can increment a variable indirectly:

<$$myvar = "$$other">

<*$$myvar++>

This sequence increments the value of $$other rather than the value of $$myvar. See §28.6.7 Using indirection in expressions.



28 Working with macros > 28.3 Using macro variables > 28.3.3 Incrementing and decrementing macro variables