If variable DOES NOT contain

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
stoavio
Posts: 43
Joined: Sun Jun 30, 2013 2:09 am

If variable DOES NOT contain

Post by stoavio » Wed Nov 05, 2014 1:49 pm

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!!

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4163
Joined: Sun Jan 07, 2007 9:12 pm

Re: If variable DOES NOT contain

Post by bn » Wed Nov 05, 2014 1:55 pm

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

magice
Posts: 457
Joined: Wed Mar 18, 2009 12:57 am

Re: If variable DOES NOT contain

Post by magice » Wed Nov 05, 2014 3:33 pm

Isn't that redundant? Doesn't the "else" work by itself?

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4163
Joined: Sun Jan 07, 2007 9:12 pm

Re: If variable DOES NOT contain

Post by bn » Wed Nov 05, 2014 3:39 pm

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

[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2262
Joined: Thu Feb 28, 2013 11:52 pm

Re: If variable DOES NOT contain

Post by [-hh] » Wed Nov 05, 2014 4:33 pm

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 :-)]
shiftLock happens

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10043
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: If variable DOES NOT contain

Post by FourthWorld » Wed Nov 05, 2014 5:27 pm

FWIW "contains" is also an operator.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

stoavio
Posts: 43
Joined: Sun Jun 30, 2013 2:09 am

Re: If variable DOES NOT contain

Post by stoavio » Fri Nov 07, 2014 12:12 pm

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

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4163
Joined: Sun Jan 07, 2007 9:12 pm

Re: If variable DOES NOT contain

Post by bn » Fri Nov 07, 2014 7:01 pm

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

Post Reply