Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!
repeat for each line tLine in tDocDocg
put item 3 of tLine & return after field "fldDoc"
## Collect all ITEMs and store it in a custom property of fld "fldDoc"
put item 1 of tLine & numtochar(2) after tAllItems1
put item 2 of tLine & numtochar(2) after tAllItems2
put item 4 of tLine & numtochar(2) after tAllItems4
put item 5 of tLine & numtochar(2) after tAllItems5
put item 6 of tLine & numtochar(2) after tAllItems6
etc...
end repeat
not directly! In case like these ARRAYS are the way to go!
ARRAYS can also be stored completely into a custom property, which is a fine thing
When you need to concatenate VARIABLE names, you will need to use DO all the stuff,
which is also a performance slowdown, so arrays come in quite handy here!
...
repeat for each line tLine in tDocDocg
## Avoid accessing FIELDS in repeat loops, that's a big slowdown!
put item 3 of tLine & return after tNewText
# Collect all ITEMs and store it in a custom property of fld "fldDoc"
# Repeat For EACH is fast but read only so we need to manage our own counter
repeat for each item tItem in tLine
## Already processed this one
if tCounterItem = 3 then
next repeat
end if
put tItem & numtochar(2) after tAllItems[tCounterItem]
## END each item...
end repeat
## END each line...
end repeat
## Now access field ONCE :-)
put tNewText after fld "fldDoc"
...
## Now set the custom property, so we can later access it:
set the cAllItems1 of fld "fldDoc" to tAllItems1
set the cAllItems4 of fld "fldDoc" to tAllItems4
To extract your values, do something like this:
...
put the the cAllItems of fld "fldDoc" into tArray
put tArray[1] into tAllItems1
put tArray[2] into tAllItems2
etc...
...
Sorry, I completely forgot to INCREMENT the custom counter -> tCounterItem
...
repeat for each line tLine in tDocDocg
## Avoid accessing FIELDS in repeat loops, that's a big slowdown!
put item 3 of tLine & return after tNewText
# Collect all ITEMs and store it in a custom property of fld "fldDoc"
# Repeat For EACH is fast but read only so we need to manage our own counter
put 1 into tCounterItem
repeat for each item tItem in tLine
## We already processed this one
if tCounterItem <> 3 then
put tItem & numtochar(2) after tAllItems[tCounterItem]
end if
## INCREMENT counter:
add 1 to tCounterItem
## END each item...
end repeat
## END each line...
end repeat
## Now access field ONCE :-)
put tNewText after fld "fldDoc"
...
Klaus' advice about using an array is correct. The sublevels of control required to do what you want is doable in LC, but inelegant. Nevertheless, since I grew up without arrays, this is with the "do" construction (that Klaus mentioned as well). I got data from a field that had several lines in it with several items in each line. A couple of changes just to make my life easier.The only value here is to see how the "do" keyword creates evaluated expressions that LC can deal with without throwing up:
on mouseUp
put fld "f3" into tDocDocg
put numtochar(2) into tChar
repeat with y = 1 to the number of lines of tDocDocg
put item 3 of line y of tDocDocg & return after field "f1"
repeat with u = 1 to the number of items of line y of tDocDocg
do "put item" && u && "of line" && y && "of tDocDocg" & "&" && tChar && "after tAllItems" & u -- this is it, folks. There are other ways to construct it
end repeat
end repeat
end mouseUp
Hi Craig,
I will keep your suggestion in case I will not able to solve something still wrong in the development of Klaus' code.
Klaus, I put the set to 1 of var. tCounterItem inside of the Repeat of each line loop. because, if I am right, the counter must start to 1 at the first item of each line.
otherwise, I obtained incorrect data.
Now, I've still something wrong. this line of code:
I already showed you how to extract the desired values from your custom property!?
You need to use ARRAY syntax, which is not "line xyz of zyx":
To extract your stored values, do something like this:
...
put the the cAllItems of fld "fldDoc" into tArray
put tArray[1] into tAllItems1
put tArray[2] into tAllItems2
etc...
...
In your example you should script something like this:
...
put the the cAllItems of fld "fldDoc" into tArray
put tArray[linenumber] into fld "fldDenomin"
...
## What line has been clicked:
put the hilitedline of me into tLineNumber
## Prepare to access custom property:
set linedel to numtochar(2)
## Now display the corresponding ITEMS in rispettivi field:
put the cAllItems of fld "fldDoc" into tArray
put tArray[2] into tAllItems2
put line tLineNumber of the tAllItems2 of me into fld "fldDenomin"
on mouseup
## What line has been clicked:
put the hilitedline of me into tLineNumber
## Prepare to access custom property:
set linedel to numtochar(2)
## Now display the corresponding ITEM 2 in another field:
put line tLineNumber of the cAllItems2 of me into fld "txtRispostaTrovata"
end mouseup
...
put the cAllItems of fld "fldDoc" into tArray
put tArray[2] into tAllItems2
## Now tAllItems2 is a VARIABLE and not a custom property!
## You treat it like a CP:
## put line tLineNumber of the tAllItems2 of me into fld "fldDenomin"
## But it is a variable:
put line linenumber of tAllItems2 into fld "fldDenomin"
...