LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!
on mouseUp
put Field "Text" into tFiles
repeat with i = 1 to the number of lines of tFiles
put "000" before line i of tFiles
put tFiles into field "Text"
end repeat
end mouseUp
I have a list of text files and want to add a number to the front of them that increases numerically ie, 001 Text, 002 Text, 003 Text, etc but I'm not sure how to write this into the above code. Can someone please show me how this is implemented?
on mouseUp
put Field "Text" into tFiles
put 0 into tCount
repeat for each line tFile in tFiles
add 1 to tCount
put format("%03d", tCount) & tFile & cr after tChangedFiles -- see the 'format' function in the docs
end repeat
delete char -1 of tChangedFiles -- delete trailing cr
put tChangedFiles into field "Text"
end mouseUp
"repeat for each" loops tend to run much faster than the "with n =..." loops, though it won't necessarily be noticeable unless your list of files is very long.
on mouseUp
put Field "Text" into tFiles
set the numberformat to "000"
put 0 into tCounter
repeat for each line aLine in tFiles
add one to myCounter
put tCounter && aLine & return after tNewFiles
end repeat
delete char -1 of tNewFiles -- remove superfluous return
put tNewFiles into field "text"
end mouseUp
Various teststacks and stuff:
http://bjoernke.com
Chat with other RunRev developers:
chat.freenode.net:6666 #livecode
on mouseUp
put Field "Text" into tFiles
set the numberformat to "000"
put 0 into tCounter
repeat for each line aLine in tFiles
add one to tCounter
put tCounter && aLine & return after tNewFiles
end repeat
delete char -1 of tNewFiles -- remove superfluous return
put tNewFiles into field "text"
end mouseUp