I am a complete newbie with Livecode, and after dabbling a bit with some examples I'd like to do the following:
In a list, I want to find a specific line that equals a value. Then subtract a number from an item in that line and replace the specific item with the new value:
repeat for each line theline in getallister
put item 1 theline & space & item 2 theline into watisnaam
if watisnaam=soekernaam then
put item 12 theline into kryverlofbalwaarde
subtract totelklyn from kryverlofbalwaarde
replace item 12 theline with kryverlofbalwaarde in getallister
end if
end repeat
Trying the above, replaces all the items corresponding to the specific criteria in the whole list with new subtracted value, and not just the specific line.
I only want to subtract a number from the specific line, in this case, item 12 of the line, and replace it with the new subtracted value.
Any help would be much appreciated.
Replacing item in line after subtracting
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
Re: Replacing item in line after subtracting
You're almost there: a couple of things:
First of all, if you're using the "for each" form of the repeat statement (and you should if you can because it's an order of magnitude faster than the other forms) then you have to treat the source (getalllister in this case) as read-only. You shouldn't expect to write things into it without crashing.
Secondly, you've almost got the syntax right for replacing the original value. Try this:
and now resultlist contains the modified getallister
First of all, if you're using the "for each" form of the repeat statement (and you should if you can because it's an order of magnitude faster than the other forms) then you have to treat the source (getalllister in this case) as read-only. You shouldn't expect to write things into it without crashing.
Secondly, you've almost got the syntax right for replacing the original value. Try this:
Code: Select all
repeat for each line theline in getallister
put item 1 of theline & space & item 2 of theline into watisnaam
if watisnaam=soekernaam then
put item 12 of theline into kryverlofbalwaarde
subtract totelklyn from kryverlofbalwaarde
put kryverlofbalwaarde into item 12 of theline
end if
put theline & cr after resultlist
end repeat
Re: Replacing item in line after subtracting
Thanks Mark!
Really appreciate it. That did it.
Just when I got to a stage where I did not know what to try anymore, you helped.
Really appreciate it. That did it.

Just when I got to a stage where I did not know what to try anymore, you helped.
Re: Replacing item in line after subtracting
Glad it worked out. The bit about the source not being modifiable is not intuitive. There's a long-standing bug in the bug database about changing that behavior, but for now it's just something that you learn as you go along and learn to live with.