Parentheses () are used in the Q++ Macro Language in the same way they are used in most languages and in math; to group together expressions which should be carried out together.

There are 2 reasons for using parentheses.

First, to make sure that expressions are calculated in the order you want, when the precedence of operators is an issue. As you may remember from high school math, multiplication and division always take precedence over addition and subtraction. So without parentheses, the following expression

-23+25 * 5-2

may yield the surprising result of 100 instead of the number 6 that the formatting might have suggested. The reason is that the above expression is interpreted as :

-23+(25*5)-2

The second, just as important, reason is to improve legibility of your code. Even when parenthese are not necessary, it is sometimes useful to use them to make your code easier to follow. Some examples :

bIsMonday = (WeekdayOf(Today() == 1)

nNextMonth = Today() + (nDaysInMonth - DayOf(Today()) + 1)

Topic 121600 updated on 01-Oct-01.

Topic URL: https://www.qppstudio.net/webhelp/index.html?parentheses.htm