I'm trying to add a simple IF
statement to my include .i
-file to handle optional unnamed parameters
:
message.i:
/*
- {1}: Message.
- {2}: OPTIONAL Sender name
*/
&IF DEFINED({2}) <> 0 &THEN
{2} = "Unknown sender".
&ENDIF.
MESSAGE "{2}" + ": " + "{1}" VIEW-AS ALERT-BOX.
test.p:
{message.i "hello world" }
// Should output "Unknown sender: hello world".
// Does not compile.
{message.i "hello world" "Michael" }
// Should output "Michael: hello world".
In this version, the message.i
will throw error if the second parameter is missing.
I want to use unnamed parameters
and avoid the parameter naming.
How I can fix the code to make it work?
You could check if the second parameter is empty :
message.i
&IF "{2}" <> "" &THEN
MESSAGE "{2}" + ": " + "{1}" VIEW-AS ALERT-BOX.
&ELSE
MESSAGE "Unknown sender" + ": " + "{1}" VIEW-AS ALERT-BOX.
&ENDIF.