I am trying to create a barcode like this one: [RP179349376CN]
As you can see in below table, when going from 9 to 10, an additional digit is added.
My question is how to guarantee the digits used are always the same amount? (the reason in column 6, I deducted manually a zero)
LeftPad would do the trick, I think. Do you know in advance how many rows you will potentially have, or is it completely dynamic?
If you know, itâs just LeftPad([Row ID], 2, "0").
If you donât, youâll have to do something a little more complex, youâll have to go through all the âRow IDsâ to find the longest one, then count the digits, and use this as your target length:
LeftPad([Row ID], [Table of IDs].Sort(false(),[Row ID]).[Row ID].First().ToText().Length(), "0")
LeftPad syntax is string, target length, filler, so if you change the second argument, youâll get what you want, I think (eg: LeftPad([Row ID], 9, "0"))
Yes, thatâs how I did it in the first solution. (see screenshot in previous post) Just for curiosity and to learn, where to set the length in this formula?
LeftPad([Row ID], [Table of IDs].Sort(false(),[Row ID]).[Row ID].First().ToText().Length(), "0")
LeftPad(
[Row ID], // This is the string you're going to pad. For example, it might be '1'
[Table of IDs].Sort( // Now I'm going to get the highest Row ID.
false(), // Sort from largest to smallest (DESC)...
[Row ID] // ... by the Row ID column
).[Row ID].First() // Now get the first row of our sorted list's row ID. In a table with 100 rows, this will be 100.
.ToText().Length(), // Now, convert the value to a string, and get the length of the string (eg: 100 => "100", which has length 3.
"0") // Now pad the string with the character 0.
So parsed out as a list of âinstructionsâ to Coda:
Get a string from the column called âRow IDâ
Get the target length of the new padded string by:
2a. Getting the âTable of IDsâ
2b. Sorting it by the Row ID column from largest to smallest
2c. Getting a list of values from the Row ID column
2d. Getting the first one
2e. Converting it to a string
2f. Getting the length of the string.
Use the character â0â to pad out the string
Take the string from step 1, and add the value from step 3 to the front of it until the string reaches the length from step 2f.