Page 1 of 1
Stuck on a if Condition.. too silly
Posted: Wed Jun 07, 2017 5:01 pm
by LutherPaul
Hi Gurus,
I am stumped on a simple if condition which fails miserably. I am reading data from a csv file.
The first condition to check for blank works and fails checking 'N/A', <>0 and ='N'.
Can someone tell me where I am going wrong?
the condition translates to
if Proj_code is not blank or proj_code is not equal to 'N/A' or Proj_code is not equal '0' or if NewBuss is equal to 'N'
if ( Proj_code @<> '' % Proj_code @<> 'N/A' % Proj_code @<> '0' % NewBuss @= 'N') ;
-----
EndIf;
I have verified that the data is 'N/A', '0'. Dont understand why the OR condition fails. Can someone please help?
Thanks,
Paul.
Re: Stuck on a if Condition.. too silly
Posted: Wed Jun 07, 2017 5:48 pm
by Michel Zijlema
LutherPaul wrote:the condition translates to
if Proj_code is not blank or proj_code is not equal to 'N/A' or Proj_code is not equal '0' or if NewBuss is equal to 'N'
if ( Proj_code @<> '' % Proj_code @<> 'N/A' % Proj_code @<> '0' % NewBuss @= 'N') ;
-----
EndIf;
I have verified that the data is 'N/A', '0'.
So you're saying the data
is 'N/A', '0' and you're checking on
is not equal to 'N/A' or
is not equal to '0'.
Isn't that your issue? Otherwise you need to be a bit more clear on what you expect to happen inside and outside of the if statement.
Michel
Re: Stuck on a if Condition.. too silly
Posted: Wed Jun 07, 2017 6:14 pm
by LutherPaul
Thanks Michel for replying.
I have bad data coming in with values like 'N/A', '0', 'ASDF', which I want to avoid.
When the data is not in ('N/A', '0', 'ASDF'), I want my if to work else, nothing.
Hope I am clear.
Thanks,
Paul.
Re: Stuck on a if Condition.. too silly
Posted: Wed Jun 07, 2017 6:18 pm
by gtonkin
As Michel said, you need ANDs , not ORs i.e. not blank and not N/A and not 0 etc.
Re: Stuck on a if Condition.. too silly
Posted: Wed Jun 07, 2017 6:20 pm
by declanr
Code: Select all
if ( Proj_code @<> '' % Proj_code @<> 'N/A' % Proj_code @<> '0' % NewBuss @= 'N') ;
With code like this you are sort of applying a double negative... if the project code is "N/A" it can't also be blank so by using an or on it; the "N/A" gets through as it is not blank or 0.
Its sometimes easier to say if something is equal to such and such then itemskip.
Re: Stuck on a if Condition.. too silly
Posted: Wed Jun 07, 2017 6:31 pm
by Wim Gielis
declanr wrote:Code: Select all
if ( Proj_code @<> '' % Proj_code @<> 'N/A' % Proj_code @<> '0' % NewBuss @= 'N') ;
With code like this you are sort of applying a double negative... if the project code is "N/A" it can't also be blank so by using an or on it; the "N/A" gets through as it is not blank or 0.
Its sometimes easier to say if something is equal to such and such then itemskip.
True. In Metadata and Data tabs with more than a handful lines of code, I tend to use Itemskip and Itemreject first.
All other cases that remain will be treated with the remaining code.
Re: Stuck on a if Condition.. too silly
Posted: Wed Jun 07, 2017 6:57 pm
by Michel Zijlema
declanr wrote:Its sometimes easier to say if something is equal to such and such then itemskip.
I second that. To me it was not clear whether the If statement enclosed an ItemSkip or the actionable code...
I would reverse the conditions and put an ItemSkip inside the if and the actionable code after the endif.
Otherwise (the actionable code still within the if) the condition should I assume be:
Code: Select all
if ( (Proj_code @<> '' & Proj_code @<> 'N/A' & Proj_code @<> '0') % NewBuss @= 'N') ;
Michel
Re: Stuck on a if Condition.. too silly
Posted: Wed Jun 07, 2017 7:53 pm
by LutherPaul
Thanks. That was stupid of me.