Page 1 of 1

Lineoffset() finding line beginnings?

Posted: Wed Jul 09, 2014 2:14 pm
by AxWald
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!

Re: Lineoffset() finding line beginnings?

Posted: Wed Jul 09, 2014 2:23 pm
by Klaus
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

Re: Lineoffset() finding line beginnings?

Posted: Wed Jul 09, 2014 2:26 pm
by AxWald
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!