English

Error: &IF returns "ERROR - Wrong Item Type. Cannot perform operation"

Solution or Workaround

Question:

Why do I get this message?

&IF returns: ERROR - Wrong Item Type. Cannot perform operation.
AML ERROR - Invalid expression on &IF directive
Causes:

1) &IF must compare values of the same type. These types can be character strings, integer values, real numbers or boolean operators. This message often occurs when quoted strings are compared to numbers or a number is compared to a null variable.

2) An &IF statement cannot compare values that are logical operators (e.g. CN, NE) or logical connectors (AND, OR).

Answer:

1) Verify the type of input before using &IF with it. You can do this using the [TYPE] function. For example:

&sv number = [RESPONSE 'Enter an integer']
&if [TYPE %number%] ne -1 &then
&return &inform You did not enter an integer

&if %number% ge 10 &then
&ty You entered a number greater than or equal to 10.

2) Quote the string that evaluates to a logical operator/keyword. You can use the [QUOTE] function to quote variables. For example:

&sv i = AND
&if [QUOTE %i%] = 'AND' &then
&ty This Works

&if %i% = 'AND' &then
&ty This does not work