Back with another quickie (I hope!)
I have an array which contains information that I am looping through and putting into files. The problem is, the name of the file needs have a particular format (number of 0's). I know LiveCode can do this but my attempts at using the format function haven't panned out.
The little loop I have for putting data from the array into files looks like this:
Code: Select all
//Isolate individual transactions and put into array
put fld "File" into fld "User"
delete line 1 to 11 of fld "User" //clear header
set the wholeMatches to true //find end of transaction
repeat 10 times
put lineOffset ("END", fld "User") into tEndTrans //determine end of transaction
put line 1 to tEndTrans of fld "User"into tTXN[i] //store transaction in array
delete line 1 to tEndTrans of fld "User" //remove processed transaction so next one can be processed
add 1 to i //increment array
wait 3 ticks
end repeat
//Separate transactions into individual files
put 1 into i
repeat for each element tTXNData in tTXN
put tTXNData into URL ("file:" & "C:\Users\User\Desktop\" & "TXN" & i & ".txt")
add 1 to i
end repeat
TXN1
TXN2
TXN3
TXN4
TXN5
TXN6
TXN7
TXN8
TXN9
TXN10
Instead, I need to format 'i' so that it intuitively knows how many zeros to place in front of the number so they look like this:
TXN00001
TXN00002
TXN00003
TXN00004
TXN00005
TXN00006
TXN00007
TXN00008
TXN00009
TXN00010
Notice how when the number increases, the number of zeros preceding it decrement by 1. Basically, I want to enforce a 5 character number eg: TXN#####
In my last piece of code I tried my hand at using format but clearly I need a push in the right direction. Can I use %[charLength].[precision]f on "i" below to get this formatted the way I want?
Code: Select all
//Separate transactions into individual files
put 1 into i
repeat for each element tTXNData in tTXN
put tTXNData into URL ("file:" & "C:\Users\User\Desktop\" & "TXN" & format("%[charLength].[precision]f",i) & ".txt")
add 1 to i
end repeat