Hi Folks,
I tried to use $ifThen ($ifThenR) and ord functions to differentiate the scenarios containing ‘s’.
So I would expect the set fest to only have one element, b. When I run the following code, fest always has two elements a, b.
Please help me figure out what went wrong.
$set Scenarios static
$ifThen (ord('%Scenarios%',1)==ord('s',1))
$set ff '*'
$else
$set ff ''
$endif
;
set fest /
%ff% a
b
/;
display fest;
[code]
Best/JG
You did a ifThen comparing the left and right string (they are obviously different) and hence you always fall into the else part. You probably want to do a ifThenE, but ord() is not part of the functions available at compile time (see https://www.gams.com/latest/docs/UG_DollarControlOptions.html#INDEX_dollar_21_control_21_options_22__25_eval). So no joy. If you insist on the “starting with s” check you will need to resort to some external feature, e.g. grep:
$set Scenarios static
$call echo %Scenarios% | grep -q "^s"
$ifThen errorlevel 0
$set ff '*'
$else
$set ff ''
$endif
set fest /
%ff% a
b
/;
display fest;