Scroll to the nearest line [Solved]

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
atout66
Posts: 266
Joined: Wed Feb 02, 2011 12:31 pm

Scroll to the nearest line [Solved]

Post by atout66 » Thu May 05, 2016 5:22 pm

Hi to all,

I've a field called "matrice" with 410 000 lines. Each line contains a word.
Above that field "matrice", I've a field called "search". The user can input a word inside.
What I want to do is, that each char placed into the field "search", I scroll the field "matrice" to the nearest right line...
Don't know if I'm clear enought :oops:

If the field "matrice" contains the words below:
londonien
londonienne
londoniennes
londoniens
Londres
long
If in my "search" field I put the chars < l - o - n - d - r > one after each other, how could I <set the hilitedLine of fld "matrice" to ???> from the first line to the line <Londres> which is the nearest from my request ? Do you see what I mean ?
Of course, they are many lines in the "matrice" field before the word <londonien> and after the word <long> shown in this example:wink:

I tried in a keyUp handler the lineOffset() function, but as I use the < set caseSensitive to true > and < set the wholeMatches to TRUE >, it doesn't work until the word in the search field is not complet.

Thanks in advance if you can help, Jean-Paul.
Last edited by atout66 on Thu May 05, 2016 8:45 pm, edited 1 time in total.
Discovering LiveCode Community 6.5.2.

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10305
Joined: Wed May 06, 2009 2:28 pm

Re: Scroll to the nearest line

Post by dunbarx » Thu May 05, 2016 5:59 pm

Hi.

Make a button, a scrolling list field and a normal field on a new card. In the button script:

Code: Select all

on mouseUp
   repeat 200
      repeat 4
         put any char of "asdfghjklpoiuytrewqzxcvbnm" after temp
      end repeat
      put return after temp
   end repeat
   put temp into fld 1
   sort fld 1
end mouseUp
Click on the button. Scroll down a bit until you find a word you like. Remember it. Now scroll back up to the top.

In the script of the ordinary field:

Code: Select all

on keyDown tKey
   put tkey after me
   get lineOffset(me,fld 1)
   set the scroll of fld 1 to it * the textheight of fld 1 - the textheight of fld 1
end keyDown
Start typing that word into the field. This should get you started.

Craig Newman

atout66
Posts: 266
Joined: Wed Feb 02, 2011 12:31 pm

Re: Scroll to the nearest line

Post by atout66 » Thu May 05, 2016 6:30 pm

Thanks for your help Craig. I tried your script without success.
I remember that this problem belong to a logarithm search and that there was a lesson somewhere about it.

I continu my research :wink:
Discovering LiveCode Community 6.5.2.

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10305
Joined: Wed May 06, 2009 2:28 pm

Re: Scroll to the nearest line

Post by dunbarx » Thu May 05, 2016 7:35 pm

I tried your script without success.
Hmmm. It cannot be that the time it takes is too long?

And I think you meant a "binary search". So it must be that my handler does not limit itself to the beginnings of words, eh?

Can you think of a way around that? If not, write back.

Craig

atout66
Posts: 266
Joined: Wed Feb 02, 2011 12:31 pm

Re: Scroll to the nearest line

Post by atout66 » Thu May 05, 2016 8:12 pm

No Craig, it's not a problem of time, I track your script via the debugger and the lineOffset() is very fast.

I don't know what is a "binary search" but when I was under Toolbook (long time ago) they had a function which used a logarithm way to find the nearest number or word or position of an object which was very usefull.

I try to find an old lesson I saw in the tuts of LC, but I still didn't find it.
When I'll do, I'll let you know ;-)

Cheers, Jean-Paul.
Discovering LiveCode Community 6.5.2.

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10305
Joined: Wed May 06, 2009 2:28 pm

Re: Scroll to the nearest line

Post by dunbarx » Thu May 05, 2016 8:20 pm

Well, try this anyway. In the "toFind" field script:

Code: Select all

on keyDown tKey
   put tkey after me
   find me in fld 1
   put word 2 of the foundLine into tLine
   set the scroll of fld 1 to tLine * the textheight of fld 1 - the textheight of fld 1
end keyDown
Is this what you wanted?

Craig

atout66
Posts: 266
Joined: Wed Feb 02, 2011 12:31 pm

Re: Scroll to the nearest line

Post by atout66 » Thu May 05, 2016 8:44 pm

Wahou ! you've got it almost !

I just replaced your line:

Code: Select all

set the scroll of fld "laMatrice" to tLine * the textheight of fld "laMatrice" - the textheight of fld "laMatrice"
by:

Code: Select all

set the hilitedLine of fld "laMatrice" to tLine -- <tLine> is the number of the line
and then it works !

Thanks very much Craig.
BTW, I found the lessons I was talking about.
It's here, the second part called "Logarithmic Search": http://lessons.livecode.com/m/4071/l/11 ... h-an-array
But this way, it use an array instead of a field

Cheers, Jean-Paul.
Discovering LiveCode Community 6.5.2.

Post Reply