How to I get clickItem?
Mark Brownell
gizmotron at earthlink.net
Sun Aug 31 14:21:00 EDT 2003
On Sunday, August 31, 2003, at 11:01 AM, Bill Vlahos wrote:
> My goal for this is to have a field with data that is structured. The
> user clicks on the item to edit the contents in another field(s) and
> replaced when the editing is done. I can't do that if I don't know
> which item was selected.
>
> Bill Vlahos
Hi Bill,
You could try a Parallel Numerical Lineal Parser in conjunction with
the htmlText capability.
Not knowing Transcript very well there is probably an easier way but
this is how I would do it not knowing for sure.
Take your items and put them inside tags sets <item><p> & </p>. You can
include <p></p> for line breaks inside your items. You then use
offset() to make a list of char locations for all instances of
"<item><p>":
Warning untested code:
global itemArray2
put yourTextToSearch into tZap
put 0 into tStart
put 1 into tElementNum
repeat
put offset("<item><p>",tZap,tStart) into tNum
put (tNum + tStart) into tStart
if tNum < 1 then exit repeat
put tStart into itemArray[tElementNum]
add 1 to tElementNum
end repeat
put the number of chars in tZap into xZap
put xZap into itemArray[tElementNum + 1]
Now you have an array of numerical values for the beginning of each
item delimiter, "<item><p>". With a little clean up math to remove the
number of chars within any tag set you will be left with the same
number of characters that are rendered in your field after using the
htmlText to present it. Use the array to make a numerically corrected
array. You now have a numerical reference to compare the char number
(the clickCharChunk) to the range that fits in the new array. In that
way you will get the item number you are looking for when a user clicks
in your field.
array clean up script:
put 1 into itemArray2[1]
repeat with xy = 1 to tElementNum
put itemArray[xy] into get1
put itemArray[xy + 1] into get2
put char get1 to (get2 - 1) of tZap into holdItemWithTags
put the htmlText of holdItemWithTags into zip
put the number of chars in zip into holdNumZip
put holdNumZip into itemArray2[xy + 1]
end repeat
-- with the already created global itemArray2
-- put this in myField script:
on mouseUp
global itemArray2
put the clickCharChunk of myField into zap
put 1 into z
repeat
if itemArray2[z] >= zap then
put z into itemNumberIs
exit repeat
end if
add 1 to z
end repeat
end mouseUp
-- you now have the item number in itemNumberIs
Mark
More information about the use-livecode
mailing list