Page 1 of 2
How to hilite a line of field by pushing first letter of a
Posted: Fri Oct 31, 2014 9:56 pm
by sphere
Hello,
i'm strungling a bit on how to hilite a line of a field by pushing the first letter of a string.
it's a field with email adresses, and of course you can just click on a line and it will be hilited.
But some people like to push on a letter corresponding to the first letter of a name.
Now i searched a lot of threads on the forum, but....
I tried a few thing and it's reacting to the key, but selects the whole field instead of just a line, and better is if a letter is pushed again it jumps to the next line beginning the caorresponding letter:
Code: Select all
on keyDown pKey
#put pKey
set the itemDelimiter to pKey
#select after chunk & pKey of field "To"
#set the hilitedLine of field "To" to pKey
select text of the target
pass keyDown
end keyDown
Hope that anyone can guide me to the right direction, i think i'm close but, a little help would be appreciated.
Thanks !
Re: How to hilite a line of field by pushing first letter of
Posted: Fri Oct 31, 2014 11:11 pm
by dunbarx
Hi.
Do I understand what you want here? Make a field with a list of a bunch of names. In a locked field, place this:
a b c d e f g... z (spaces between each letter)
In the field script:
Code: Select all
on mouseup
find the clickText in fld 1
end mouseup
Now this is going to be OK with a few names, and those names perhaps ought to be sorted, but will be impotent with a long list. It only works in the first place because the nature of the unadorned "find" command looks only at the beginnings of words.
Craig Newman
Re: How to hilite a line of field by pushing first letter of
Posted: Sat Nov 01, 2014 7:35 pm
by sphere
Hi Craig,
it's not a mouse issue. With the mouse you can select an entry or line and that one is hilited. Only one can be hilited.
When an email address is added then at every entry the field is sorted directly alphabetically. This is all working ok.
I'm trying to get a line hilited when someone pushes a letter an their keyboard which corresponds to the first letter of the email address.
so if you push t the line wil go to
t@blabla.com, push again t go to the next
ta@blabla.com and the same for other letters
thanks for your idea!
Re: How to hilite a line of field by pushing first letter of
Posted: Sat Nov 01, 2014 10:28 pm
by dunbarx
Oh, that is what you meant by "push a letter". I would have said, "press a key".
In a card script, place this:
Code: Select all
on keydown var
put var
end keydown
With the card window in front, press a few keys. Now, can you make this work for your list field?
Craig
Re: How to hilite a line of field by pushing first letter of
Posted: Sun Nov 02, 2014 12:26 am
by sphere
Hello Craig,
yes normally i would also say push key, but i read some threads and people were talking about letters so i thought well maybe they talk about it here like that.
Ok your piece of code, i tried something similair too, see my code above but i # it out. A field is coming up showing the key you just pushed. I came so far too.
I'm having trouble to let a line hilite when psuhing it. I also tried, something simple like if pKey then hilite the line of field"To" etc.
So i can get the whole field selected but not yet a single line selected which refers to the first character of the email address.
So i need a bit of guidance on how to do that.
Thanks for your assistance !
Re: How to hilite a line of field by pushing first letter of
Posted: Sun Nov 02, 2014 12:40 am
by dunbarx
Hi.
A field is coming up? "Put", alone as I wrote (put var), will place the letter in the message box.
Make a field with a bunch of names. Put this in the card script:
Code: Select all
on keydown var
find var in fld 1
end keydown
Make sure the card window is in front. Press a key.
Now I get the feeling that you are still ahead of this. So please write back and tell us what you still need.
Craig
Re: How to hilite a line of field by pushing first letter of
Posted: Sun Nov 02, 2014 12:59 am
by sphere
Hi Craig,
yes that's exactly it! Great! You hit the jackpot!
Thanks a lot!
Next step for me is to use a pull down menu and make sure the last selected item will be the same as the program restarts.
Up to the next quest

edit: this is for later i guess.....
because something strange is happening
sometimes it finds the line and sometime it finds the key and draws a square around it and selects the entry at the top. So why is not selecting the line were the key is found. Strange thing is 1 or 2 times it does work and selects the line which has the key.
any idea why it behavious like this?
Thanks a lot !
Re: How to hilite a line of field by pushing first letter of
Posted: Sun Nov 02, 2014 3:17 am
by dunbarx
You need to familiarize yourself with the "find" command. There are several variants of this, and only some may be appropriate. Depending on the foundText, you may see the different results I think you are describing.
That said, "find" is being stretched to the limit to do what you want. For example, you may already have found that pressing a particular letter twice will find the second instance of a name in the list. What I am trying to get across is that you will have to accommodate the way that command works to your purpose, as opposed to having that command do your bidding. I hope that is not too opaque.
It is a good idea to do just a bit of extra work to insure that the whole line is selected after a find, instead of simply letting the boxed text indicate the found text in that line. Can you do this? And what about doing it all in an entirely different way? Any ideas? You would still use the "keyDown" message to start.
You can set a custom property to remember the "foundLine", and recall it later. Please read about this function in the dictionary. Custom properties survive sessions.
Craig
Re: How to hilite a line of field by pushing first letter of
Posted: Sun Nov 02, 2014 10:57 am
by sphere
Thank you Craig for your explanations, really appreciate it.
I will check the dictionary and play a bit to see if i can get it fit to what i need.
Maybe i can get it done to get the whole line selected.
I will get back to show what i'v done.
Thanks a lot !
Re: How to hilite a line of field by pushing first letter of
Posted: Sun Nov 02, 2014 1:52 pm
by sphere
Hi Craig,
i tried a few things and the line gets selected but if i push the same key again i get an error in the line: if var is not empty then select the foundLine
Code: Select all
on keydown var # this works
#find var in me
find word var in me
if var is not empty then select the foundLine
if var is empty then exit keydown
#set the hilitedLine of me to line tLine
#matchText (var,"([a-z])")
#lineOffset var
end keydown
Thanks for helping.
Re: How to hilite a line of field by pushing first letter of
Posted: Sun Nov 02, 2014 9:29 pm
by dunbarx
Hi.
Well, you have a few issues. More important to me is that you learn, by stepping through the handler, how to deal with those issues.
You do step through, right? Breakpoint, right?
Good. So when you monitor the variable pane, you will see several things. First, when you "find word...", did you notice that nothing was found? Do you know why? Read again about what the "find word" variant does.
Now after fixing that, and I will give you one freebie here, (lose the word "word") the line is selected.
Why indeed does the handler throw an error after repeated finds? Make sure that your text has a couple of names with the same first letter. Run the corrected script. Watch the field. while you step through the handler. What do you think? This is really unfair to you, since it involves a peculiarity with the find command that does not exist when you are searching cards, as opposed to fields. So another freebie. Put this in place of line 3:
Code: Select all
if the result is empty then select the foundLine
"The result"??? Lots to talk about. How do we fix that, er, lost "found"? Write back. This is the very best and only way to learn.
Craig
Re: How to hilite a line of field by pushing first letter of
Posted: Sun Nov 02, 2014 10:37 pm
by sphere
Great, thanks for your comment Craig.
lots of thing to think about. Tomorrow i will continue, because when you're awake. i sleep
Will be back as i evolve in this material.
Thanks for the directions!
Re: How to hilite a line of field by pushing first letter of
Posted: Mon Nov 03, 2014 8:14 pm
by sphere
Hello Craig,
i read a bit, and if the result would not be empty it would contain error messages. (am i correct?)
Been trying a few things and this seems almost doing it's job except for still finding the keys after the @.
Code: Select all
on keydown var
#set the itemDelimiter to "@"
set the lineDelimiter to "@"
put var
# find normal var in -1 of me #this gives an error
find normal var in me
if the result is empty then select the foundLine
pass keyDown
end keydown
You do step through, right? Breakpoint, right?
uh euh i really don't know. I do it in steps but the breakpoint...
Thanks.
Re: How to hilite a line of field by pushing first letter of
Posted: Mon Nov 03, 2014 10:50 pm
by dunbarx
Hi.
Um, "-1 of me"?
That is very odd. I am surprised it compiles. Lose, it, and the handler works the same. So, lose it. Anyway, it seems to do no harm, and for me throws no error. But I am not sure what you intended...
This is getting close. Your test for the "result" is spot on. What to do about that wasted find, at the end of the list of finds? To be honest, I am not sure why finding in a field acts this way. But there are kluges that will make LC do our bidding. Hint: the problem is that at the end of a series of finds, the internal index that is updated by all the previous finds does not seem to recycle back to the beginning, as it does with searching cards. So how do we make that happen? This is not the first occasion where LC needs a little disciplining, so it does get spoiled.
Anyone out there see this effect, that if you limit a find to a particular field, the index does not "wrap" back to the beginning, as it does when finding amongst cards?
Craig
Re: How to hilite a line of field by pushing first letter of
Posted: Tue Nov 04, 2014 10:14 am
by sphere
Hi Craig,
with the '-1 of me' i tried to delimited it so it will not search behind the "@" characters, because if you push C key then it finds all the com of
blabla@blabla.com. But that's still not working and still finds behind the @.
The repeat seems to be working as it's starting again on the top of the field.
I noticed that if a found key is in the last line of that key, then if the same key is pressed again nothing happens, until it is pressed.
the code now is:
Code: Select all
on keydown var # this works-almost ok
repeat for 1 time
set the itemDelimiter to "@"
#set the lineDelimiter to "@"
put var
find normal var in me
if the result is empty then select the foundLine
if the result is the last item of var then do nothing # added so it just stays put if it was found behind the @ but's not working
next repeat
pass keyDown
end repeat
end keydown
thanks for your directions, it makes me think and puzzle
best!