Empty strings in if statements
Posted: Wed Dec 19, 2012 5:48 am
I have come across a rather counter-intuitive behavior in EViews. I presumed (and believe that most users would do the same) that this code
would result in the two dialog boxes both reading "%name is NOT Fredrik". No value has been assigned to the string variable %name, which means it is equal to "", which in turn is not equal to "Fredrik".
However, both of if statements return false and the first dialog box thus reads "%name is Fredrik". In order for the first if statement to return true, in line with my intuition, it needs to be rewritten as
Code: Select all
if %name<>"Fredrik" then
@uiprompt("%name is NOT Fredrik")
else
@uiprompt("%name is Fredrik")
endif
if %name="Fredrik" then
@uiprompt("%name is Fredrik")
else
@uiprompt("%name is NOT Fredrik")
endifHowever, both of if statements return false and the first dialog box thus reads "%name is Fredrik". In order for the first if statement to return true, in line with my intuition, it needs to be rewritten as
Code: Select all
if @isempty(%name) or %name<>"Fredrik" then
@uiprompt("%name is NOT Fredrik")
else
@uiprompt("%name is Fredrik")
endif