|
Contents |
Top Previous Next |
|
One can test the contents of a control variable by using several syntax forms below
$If %controlvariablename% == texttocompare statementtoexecute; $If %controlvariablename%" == "texttocompare" statementtoexecute; $If "%controlvariablename%" == texttocompare statementtoexecute; $If "%system.environmentvarname%" == "texttocompare" statementtoexecute; Notes:
Examples: *texttocompare $Setglobal controlvariablename comparethistext $If %controlvariablename% == "comparethistext" type1=ok; $If %controlvariablename% == comparethistext type2=ok; $If "%controlvariablename%" == "comparethistext" type3=ok; $If "%controlvariablename%" == comparethistext type4=ok;
*add spaces $Setglobal controlvariablename compare this text $If "%controlvariablename%" == "compare this text" type1=ok; $If "%controlvariablename%" == compare this text type2=ok;
generates code that after compilation and looks like the following
39 *texttocompare 41 type1=ok; 42 type2=ok; 43 type3=ok; 44 type4=ok; 45 46 *add spaces 47 type1=ok;
This code shows that the quoted or uncontrolled quoted control variable name and target text works when spaces are not present. If spaces are present then the text retrieved by use of %controlvariablename% must be encased in quotes and if the comparison is to work so must be the target text.
Often one may wish to see if the text for an item is blank. This is frequently done with commands like the following
$If "%controlvariablename%a" == "a" display "blank it is"; $If not "%controlvariablename%a" == "a" display "it is not blank";
which contain the element "%controlvariablename%a" that reduces just to "a" if the named control variable does not have a text entry.
Examples employing the environmental variables appear in environvar.gms. |