Limiting the scope of a loop in a field

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
glenn9
Posts: 220
Joined: Wed Jan 15, 2020 10:45 pm
Location: Europe

Limiting the scope of a loop in a field

Post by glenn9 » Sun Apr 11, 2021 3:39 pm

Dear All,

I have a scrolling list field that I want to loop through the lines of, but I want the loop to be restricted to just those lines that are in view by virtue of the scroll position. My first attempt was simply to do this:

Code: Select all

...
put 1 into tLineNumber
repeat for each line x in field "A"
       -- do stuff
add 1 to tLineNumber
end repeat
...
but this of course will loop through the lines of the entire field, whether they are in view or not.

Grateful for any tips in how to limit the loop to just those lines that are in view.

Many thanks,

Glenn

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2718
Joined: Sat Dec 22, 2007 5:35 pm
Location: Genève
Contact:

Re: Limiting the scope of a loop in a field

Post by jmburnod » Sun Apr 11, 2021 6:21 pm

Hi Glenn,
Here is one way to.
Is the user able to scroll your fld list ?
If that is the case you'll have to manage (or prevent) the user stop scroll between two lines.

This function get the number of the line at top and the num of allowed visible lines .

Code: Select all

on mouseup
   put getVisLine(myFldList)
end mouseup

function getVisLine pFld
   put the vscroll of fld pFld into tScroll
   put the height  of fld pFld into TH
   put the effective textheight  of fld pFld into tTH
   put the margins of fld pFld  into tMarg
   put round((tScroll/tTH) + 1) into tNoLi -- the num of line at top
   put round((tH-tMarg)/tTh) into tNbLi -- the num of allowed line regarding fld height
   return tNoLi & "," & tNbLi
end getVisLine
Best regards
Jean-Marc
https://alternatic.ch

glenn9
Posts: 220
Joined: Wed Jan 15, 2020 10:45 pm
Location: Europe

Re: Limiting the scope of a loop in a field

Post by glenn9 » Mon Apr 12, 2021 7:41 am

Jean-Marc,

Many thanks for your help and your code example - I'll work through this.

Yes, I was envisaging that the user would be able to scroll, and the loop test the condition of what is currently viewable in the field.

Kind regards,

Glenn

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”