[Use-revolution] Re: I Don't Understand Why This Is
Jeanne A. E. DeVoto
jeanne at runrev.com
Mon Nov 26 01:14:03 EST 2001
At 9:49 PM -0800 11/23/2001, Mark MacKenzie (Shaw) wrote:
>on mouseup
> local NumberOfOpenStacks
> put empty into NumberOfOpenStacks
> put empty into field "Card ID"
> put the number of lines of field "Open Stacks" into NumberOfOpenStacks
> put the number of lines of field "Open Stacks" into message
> if NumberOfOpenStacks > 0 then
> repeat until NumberOfOpenStacks = 0
> put the cardIDs of stack (line NumberOfOpenStacks of field "Open
>Stacks") & "," & (line NumberOfOpenStacks of field "Open Stacks") after
>field "Card ID"
> if NumberOfOpenStacks > 1 then
> put return after field "Card ID"
> end if
> subtract 1 from NumberOfOpenStacks
> put NumberOfOpenStacks into message
> end repeat
> end if
>end mouseup
>
>Resulting in these results in:
> Field Card ID
>
>1002 <--- This should have a "," & "BookCover"
>1013,BookCover
>1002,Variable Tracker
>1002,ThumbnailScroller
>1002,FullScreenViewer
>1002,Illustrations
>1002,ImageBank
>1002 <--- This should have a "," & "Chapters"
>1004 <--- This should have a "," & "Chapters"
>1007,Chapters
The problem is that you have multiple cards in one stack, and this line:
>put the cardIDs of stack (line NumberOfOpenStacks of field "Open
>Stacks") & "," & (line NumberOfOpenStacks of field "Open Stacks") after
>field "Card ID"
only takes one card into account. For example, suppose we come to the line
"BookCover" of the "Open Stacks" field. BookCover has two cards, ID 1002
and ID 1013. So the cardIDs of stack "BookCover" is:
1002
1013
Then you append the stack's name, with a comma, after the card IDs, and get
1002
1013,BookCover
which is what in fact appears in the field.
If you want to place the stack's name after each ID, you need to loop over
each line in the cardIDs:
put the cardIDs of \
stack (line NumberOfOpenStacks of field "Open Stacks") \
into myCardIDs
repeat with each line thisLine of myCardIDs
put thisLine,line NumberOfOpenStacks of field "Open Stacks" \
after field "Card ID"
end repeat
This ensures that the stack name is placed after each line of the cardIDs,
not just the last.
(A note about efficiency: it's much, much faster to get data from and put
data into a variable than a field. So to speed things up, when you're
working with the contents of a field, it pays in time savings to put the
field into a variable at the beginning, modify the variable as needed, then
put the variable into the field at the end. That way, you only have the
speed hit twice, rather than every time you put or get data. For example,
you could rewrite your handler above like this for more speed:
on mouseup
local NumberOfOpenStacks
put field "Open Stacks" into myOpenStacks -- <<<
put empty into NumberOfOpenStacks
put empty into field "Card ID"
put the number of lines of myOpenStacks into NumberOfOpenStacks
if NumberOfOpenStacks > 0 then
repeat until NumberOfOpenStacks = 0
put the cardIDs of stack \
(line NumberOfOpenStacks of myOpenStacks) into myCardIDs
repeat with each line thisLine of myCardIDs
put thisLine,line NumberOfOpenStacks of myOpenStacks \
after cardIDsList
end repeat
if NumberOfOpenStacks > 1 then
put return after cardIDsList
end if
subtract 1 from NumberOfOpenStacks
put NumberOfOpenStacks into message
end repeat
end if
put cardIDsList into field "Card ID" -- <<<
end mouseup
--
Jeanne A. E. DeVoto ~ jeanne at runrev.com
http://www.runrev.com/
Runtime Revolution Limited - Power to the Developer!
More information about the use-livecode
mailing list