If and repeat problem...methinks

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
oldummy
Posts: 78
Joined: Mon Jun 13, 2016 3:21 pm

If and repeat problem...methinks

Post by oldummy » Thu Jan 11, 2024 2:26 pm

Livecode Community 9.6

I have a test stack that has 5 cards. On each card there are two grouped fields.The backgroundbehavior of this group is set to true.
My intention is to run through the stack and check to see if any of those fields in this stack contain the current year.
I cannot get this script to work in any of four ways I write it.
Of these fields, only one contains 2024.
When I step through the debugger, tcount is always 5 or 0 instead of 1 or 4 depending on which option I choose use.
I'm sure it is something simple. I'm just a lot simpler than that.



Code: Select all

on mouseUp
   put the long date into tmydate
   set the itemdelimiter to ","
   put the last item of tmydate into tzzz-- I break things down into small parts just to watch them
   put "0" into tcount -- this to watch in the debugger.
   repeat with i = 1 to the number of cds of this stack --5 cds with the same grouped flds with background behavior set to true.
      --if tzzz is in fld "plop" of cd i then-- this does not work. if statement is ignored 
      if tzzz is not in fld "plop" of cd i then--this does not work. if statement is ignored
         --if tzzz is not in fld "plop" then --this does not work. if statement is ignored
         add 1 to tcount
      end if
   end repeat
end mouseUp

Klaus
Posts: 13829
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: If and repeat problem...methinks

Post by Klaus » Thu Jan 11, 2024 2:38 pm

Hi oldummy,

Code: Select all

...
put the last item of tmydate into tzzz
...
tzzz is now: " 2024" -> with a leading SPACE!
And I presume that SPACE is not in one of your fields, right?
Try this:

Code: Select all

...
put the last item of tmydate into tzzz
replace " " with "" in tzzz
...
Best

Klaus

oldummy
Posts: 78
Joined: Mon Jun 13, 2016 3:21 pm

Re: If and repeat problem...methinks

Post by oldummy » Thu Jan 11, 2024 3:15 pm

AHA! I would have gone for years without that crossing my mind.
Thank you yet again.

jiml
Posts: 336
Joined: Sat Dec 09, 2006 1:27 am
Location: Los Angeles

Re: If and repeat problem...methinks

Post by jiml » Fri Jan 12, 2024 6:54 pm

This one liner might work too.

Code: Select all

put the last trueword of tmydate into tzzz

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”