Translate metadata to field content
Mark Waddingham
mark at livecode.com
Thu Feb 20 03:13:07 EST 2020
Of course *all* three of my suggested approaches are wrong - I messed up
the inner loop in each...
On 2020-02-20 07:56, Mark Waddingham via use-livecode wrote:
> NON-UNIQUE ANCHORS
> repeat with i = 1 to the number of elements in tDataA
> local tRunsA
> put tDataA[i]["runs"] into tRunsA
> repeat with j = 1 to the number of elements in tRunsA
> if tRunsA[j]["metadata"] is tSearchText then
> repeat with m = 1 to j
> add the number of words of tRunsA[m]["text"] to tNumWords
> put true into tFlagExit
> exit repeat
> end repeat
> end if
> end repeat
> if tFlagExit then
> exit repeat
> end if
> end repeat
> select word tNumWords of line i of field "x"
Should be:
repeat with i = 1 to the number of elements in tDataA
local tRunsA
put tDataA[i]["runs"] into tRunsA
repeat with j = 1 to the number of elements in tRunsA
if tRunsA[j]["metadata"] is tSearchText then
repeat with m = 1 to j
add the number of words of tRunsA[m]["text"] to tNumWords
end repeat
put true into tFlagExit
exit repeat
end if
end repeat
if tFlagExit then
exit repeat
end if
end repeat
select word tNumWords of line i of field "x"
> UNIQUE ANCHORS
> repeat for each key i in tDataA
> local tRunsA
> put tDataA[i]["runs"] into tRunsA
> repeat for each key j in tRunsA
> if tRunsA[j]["metadata"] is tSearchText then
> repeat with m = 1 to j
> add the number of words of tRunsA[m]["text"] to tNumWords
> put true into tFlagExit
> exit repeat
> end repeat
> end if
> end repeat
> if tFlagExit then
> exit repeat
> end if
> end repeat
> select word tNumWords of line i of field "x"
Should be:
repeat for each key i in tDataA
local tRunsA
put tDataA[i]["runs"] into tRunsA
repeat for each key j in tRunsA
if tRunsA[j]["metadata"] is tSearchText then
repeat with m = 1 to j
add the number of words of tRunsA[m]["text"] to tNumWords
end repeat
put true into tFlagExit
exit repeat
end if
end repeat
if tFlagExit then
exit repeat
end if
end repeat
select word tNumWords of line i of field "x"
> RUN WITH METADATA DEFINES SELECTION - NON-UNIQUE SEARCH
>
> repeat with i = 1 to the number of elements in tDataA
> local tRunsA
> put tDataA[i]["runs"] into tRunsA
> repeat with j = 1 to the number of elements in tRunsA
> local tRunA
> put tRunsA[j] into tRunA
> if tRunA["metadata"] is tSearchText then
> repeat with m = 1 to j - 1
> add the number of codeunits of tRunsA[m]["text"] to
> tNumCodeunitsBefore
> put the number of codeunits in tRunA["text"] into tNumCodeunits
> put true into tFlagExit
> exit repeat
> end repeat
> end if
> end repeat
> if tFlagExit then
> exit repeat
> end if
> end repeat
> select codeunit tNumCodeunitsBefore to tNumCodeunitsBefore +
> tNumCodeunits - 1 of line i of field "x"
Should be:
repeat with i = 1 to the number of elements in tDataA
local tRunsA
put tDataA[i]["runs"] into tRunsA
repeat with j = 1 to the number of elements in tRunsA
local tRunA
put tRunsA[j] into tRunA
if tRunA["metadata"] is tSearchText then
repeat with m = 1 to j - 1
add the number of codeunits of tRunsA[m]["text"] to
tNumCodeunitsBefore
end repeat
put the number of codeunits in tRunA["text"] into tNumCodeunits
put true into tFlagExit
exit repeat
end if
end repeat
if tFlagExit then
exit repeat
end if
end repeat
select codeunit tNumCodeunitsBefore to tNumCodeunitsBefore +
tNumCodeunits - 1 of line i of field "x"
Oops!
Mark.
--
Mark Waddingham ~ mark at livecode.com ~ http://www.livecode.com/
LiveCode: Everyone can create apps
More information about the use-livecode
mailing list