Lineoffset() finding line beginnings?

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
AxWald
Posts: 578
Joined: Thu Mar 06, 2014 2:57 pm

Lineoffset() finding line beginnings?

Post by AxWald » Wed Jul 09, 2014 2:14 pm

Hi,

something is blocking my brain. I searched the dictionary, I googled at my best knowledge, nothing found.
Maybe some kind soul can help me with a one-liner?

Problem:
I have a locked field (MyFld), that contains multiple lines of entries.
I have an input field, and whenever something is written in, it should jump to the first line of MyFld where the line begins with what I typed.

Basically: Find the first line of fld MyFld that starts with my searchstring (= text of input field, at keydown), and return the line_number.
So I can set the selection in MyFld and scroll appropriately.

Tried:

Code: Select all

on keydown what
   [!]get the lineoffset(what, fld MyFld)[/!] -- <- Problem: This returns \ 
     the first line where what is in, not the first line starting with what ...
   select line it of fld MyFld
   set the vscroll of fld MyFld to 24*it
   pass keydown
end keydown
I know it's possible, have done it in HyperCard in many cases - but don't have my old Mac-code available anymore :/ And maybe I did it with a CompileIt! XFCN ...

It's only the first line of this script that is the problem! I know I can script it somehow, but I'm sure there's a built in function for this - am I wrong?

Else I'd write something like:

Code: Select all

repeat with i = 1 to the number of lines of MyFld
if char 1 to length(what) of line i of fld MyFld = what then

I just fear this would be slow - there must be a function to do it, and I'm just too much blocked to find it ...

Thx for any help!
All code published by me here was created with Community Editions of LC (thus is GPLv3).
If you use it in closed source projects, or for the Apple AppStore, or with XCode
you'll violate some license terms - read your relevant EULAs & Licenses!

Klaus
Posts: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Lineoffset() finding line beginnings?

Post by Klaus » Wed Jul 09, 2014 2:23 pm

HI axwald,

the trick is to "cheat" a bit:
...
on keydown what
put CR & what into tWhat
put CR & fld "myFld" into tWhere
put lineoffset(tWhat, tWhere) into tLine
...
:D


Best

Klaus

AxWald
Posts: 578
Joined: Thu Mar 06, 2014 2:57 pm

Re: Lineoffset() finding line beginnings?

Post by AxWald » Wed Jul 09, 2014 2:26 pm

Hi,
Klaus wrote:HI axwald,

the trick is to "cheat" a bit:
...
Thx so much! This forum is actually completely insanely awesome!

Have a good time!
All code published by me here was created with Community Editions of LC (thus is GPLv3).
If you use it in closed source projects, or for the Apple AppStore, or with XCode
you'll violate some license terms - read your relevant EULAs & Licenses!

Post Reply