Page 1 of 1

If variable DOES NOT contain

Posted: Wed Nov 05, 2014 1:49 pm
by stoavio
Good morning everybody -

I'm embarrassed to even ask this one, because it seems so simple, but I have been getting jammed up on it for at least 30 minutes.

I have a little piece of code that is checking a list of files for the presense of a string, and if that string is present, then I put it into a variable called lPrimaryAcct. If that string isn't present, the file goes into a variable called lDelegateAcct. It is apart of my logic to determine which account is the main/default account in Outlook.

Code: Select all

  //Loop to match OST file to config file
   repeat for each line tOSTFile in tOSTList

      //Set the primary account if there is match
      if tConfigList contains tOSTFile then
         put tOSTFile into lPrimaryAcct
      else 
         --Classify any other accounts as Delegate accounts
         put tOSTFile after lDelegateAcct
      end if
      
   end repeat
I basically want to do the opposite of "contains" (eg: "does not contain") but cannot figure out how. Basically I pictured something like this, although I understand it is not syntactically correct:

Code: Select all

  //Loop to match OST file to config file
   repeat for each line tOSTFile in tOSTList

      //Set the primary account if there is match
      if tConfigList contains tOSTFile then
         put tOSTFile into lPrimaryAcct
      else if tConfigList does not contain tOSTFile then
         --Classify any other accounts as Delegate accounts
         put tOSTFile after lDelegateAcct
      end if
      
   end repeat
Thank you!!

Re: If variable DOES NOT contain

Posted: Wed Nov 05, 2014 1:55 pm
by bn
Hi stoavio,

try

Code: Select all

if not (tConfigList contains tOSTFile) then
the parentheses force an evaluation to a boolean and you test if it is not true.

Kind regards
Bernd

Re: If variable DOES NOT contain

Posted: Wed Nov 05, 2014 3:33 pm
by magice
Isn't that redundant? Doesn't the "else" work by itself?

Re: If variable DOES NOT contain

Posted: Wed Nov 05, 2014 3:39 pm
by bn
Hi magice,
Isn't that redundant? Doesn't the "else" work by itself?
I think so too. But I wanted to give the format for "if variable does not contain" as per title of this thread regardless of the actual piece of code.
And that IS kind of tricky.

Kind regards
Bernd

Re: If variable DOES NOT contain

Posted: Wed Nov 05, 2014 4:33 pm
by [-hh]
Another possibility, following directly my german dialect of british english:

B is in A -- checks if A contains B
B is not in A -- checks if A doesn't contain B

[Bernd, I'm currently a few miles closer to north than you :-)]

Re: If variable DOES NOT contain

Posted: Wed Nov 05, 2014 5:27 pm
by FourthWorld
FWIW "contains" is also an operator.

Re: If variable DOES NOT contain

Posted: Fri Nov 07, 2014 12:12 pm
by stoavio
magice wrote:Isn't that redundant? Doesn't the "else" work by itself?
I know! Weird huh? The else isn't working by itself. I have an tOstFile that IS found in tConfigList and one that isn't. That means I should have 1 tOSTFile being put into lPrimaryAcct and another into lDelegateAcct, but what's happening is the tOSTFile that is going into lPrimaryAcct is ALSO being inserted into tDelegate.

I may likely have something wrong with my code, but I wanted to be as specific as possible so I will try BNs suggestion. :D

Re: If variable DOES NOT contain

Posted: Fri Nov 07, 2014 7:01 pm
by bn
Hi Slavio,

it is very unlikely that the "else" is not working if your test is ok.
I assume if you don't have a hit then there is more likely something wrong with your data than with If-then-else.

Maybe a leading space, a tab or something.

If your lists look ok you could try

Code: Select all

if tConfigList contains word 1 to - 1 of tOSTFile
this would eliminate space or non-printing characters in tOSTList to be compared against tConfigList.

Kind regards
Bernd