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!
put empty into tFilesWithoutExtPng
put ".png" into textToDelete
repeat for each line temp in tFiles
if char -4 to -1 of temp = textToDelete then
delete char -4 to -1 of temp
end if
put temp & cr after tFilesWithoutExtPng
end repeat
delete char -1 of tFilesWithoutExtPng
put tFilesWithoutExtPng
...
repeat for each line tLine in tFiles
## You cannot change tLine!
if tLine ends with ".png" then
## Does not work:
## delete char -4 to -1 of tLine
put char 1 to -5 of tLine & CR after tNewList
end if
end repeat
## get rid of trailing CR
delete char -1 of tNewList
...
...
put fld 1 into tFiles
put empty into tFilesWithoutExtPng
put ".jpg" into textToDelete
repeat for each line temp in tFiles
if char -4 to -1 of temp = textToDelete then
delete char -4 to -1 of temp
end if
## !!!
put temp & cr after tFilesWithoutExtPng
end repeat
...
...
put fld 1 into tFiles
put empty into tFilesWithoutExtPng
put ".jpg" into textToDelete
repeat for each line temp in tFiles
if char -4 to -1 of temp = textToDelete then
delete char -4 to -1 of temp
end if
## !!!
## put temp & cr after tFilesWithoutExtPng
end repeat
...
then tFiles is NOT altered after the loop!
So to avoid surpises I always treat "repeat for each xxx" as completely read only!
In earlier versions of LC you couldn't change the variable in the counter loop. That was changed some versions ago and now you (reportedly) can. The dictionary mentions this, but I've not tried it yet. Like Klaus, I've been too accustomed to the old way to take any chances.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
In "repeat for each...", the variable instance can be modified as often as desired. It lives apart from the loop construct. What is it that cannot be changed? What is it in the construction that "should" be "read only"
@Jacque. It sounded to me like your post referred to "repeat with..." where the index (I think) used to be sacrosanct. But now one can:
repeat for each line temp in tFiles
put temp into temp2
if temp2 contains ".png" then
delete char -4 to -1 of temp2
if temp2 = currentDay then
set the filename of image "imgDay" to defaultFolder & "/days/" & temp
exit repeat
end if
end if
end repeat
...
repeat for each line temp in tFiles
## do whatever you want to with temp:
delete char -4 to -1 of temp
## if temp was -> my_image.jpg
## then it now is in fact -> my_image
end repeat
...
You can modify temp and do with it whatever you like, but the "container" (tFiles in this case) will NOT change in the end, means tFiles BEFORE the loop = tFiles AFTER the loop.
It is always difficult to explain something like this in your non-native language.