Page 1 of 1

get line x of item y fails

Posted: Fri May 08, 2015 10:58 am
by pderks
Dictionary says: "A single item can contain multiple characters, multiple words, and multiple lines."

Code: Select all

put "a,b" & cr & "c,d,e" into DataX
put DataX & cr & cr into msg
put item 2 of DataX into ItemX
put ItemX & cr & cr after msg
put line 2 of ItemX & cr & cr after msg
but :

Code: Select all

put line 2 of item 2 of DataX after msg
results in:
"Script compile error: Error description: Chunk: bad chunk order (must be small to large)"

Peter

Re: get line x of item y fails

Posted: Fri May 08, 2015 1:08 pm
by Dixie
nearly there...:-)

Code: Select all

put item 2 of line 2 of DataX after msg

Re: get line x of item y fails

Posted: Fri May 08, 2015 3:28 pm
by dunbarx
Hi.

Unlike with HC, the LC parser will not allow you to extract a "larger" chunk from a "smaller" one. The order must be hierarchal, char, word, item, line, container. In one way this makes sense; how could you ask for the third line of the second character? HC would have returned empty with such a request. LC throws an error.

But HC would allow you to extract the second item from the second word ("aa bb,cc,dd ee" would give "cc"). So this flexibility may in fact make sense in many cases, but is still proscribed in LC. It surely derives from a more rigorous parser, in the interest of robustness and speed.

Craig Newman

Re: get line x of item y fails

Posted: Sat May 09, 2015 1:50 am
by pderks
Hi Craig,

cordial thanks for your profound & exhausting answer to an old HyperCardist | HyperCardian.

Peter

Re: get line x of item y fails

Posted: Thu Apr 15, 2021 12:48 pm
by Fermin
I think that using parenthesis can do the trick...

Code: Select all

put line 2 of (item 2 of DataX) after msg

Re: get line x of item y fails

Posted: Thu Apr 15, 2021 2:52 pm
by dunbarx
Fermin.

Correct, that is the standard way out of that restriction. The engine resolves the contents of the parens, and all is then well.

Craig