Empty strings in if statements

For notifying us of what you believe are bugs or errors in EViews.
Please ensure your copy of EViews is up-to-date before posting.

Moderators: EViews Gareth, EViews Moderator

paues
Posts: 169
Joined: Fri Apr 15, 2011 7:16 am
Location: Stockholm, Sweden

Empty strings in if statements

Postby paues » 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

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")
endif


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 @isempty(%name) or %name<>"Fredrik" then
@uiprompt("%name is NOT Fredrik")
else
@uiprompt("%name is Fredrik")
endif

EViews Gareth
Fe ddaethom, fe welon, fe amcangyfrifon
Posts: 13312
Joined: Tue Sep 16, 2008 5:38 pm

Re: Empty strings in if statements

Postby EViews Gareth » Wed Dec 19, 2012 8:51 am

As outlined in the manual, you should use @eqna to test for equality of strings, not "=" or "<>".
Follow us on Twitter @IHSEViews

paues
Posts: 169
Joined: Fri Apr 15, 2011 7:16 am
Location: Stockholm, Sweden

Re: Empty strings in if statements

Postby paues » Wed Dec 19, 2012 8:58 am

I missed that. Thank you!


Return to “Bug Reports”

Who is online

Users browsing this forum: No registered users and 17 guests