# Conditional Number Of Leading Zeros 追蹤

Legacy Poster

Hi Guys

I need to create a template that will work with a variable no of batch sizes (e.g. could be 1,000, 10,000, 100,000 records in a batch). Our manufacturing guys want the number of digits to be the same and the card no (and 3 other numeric fields for cartons and skids) to be padded with zeros to the length of longest field

For example,

if there are 1,000 records I need to use 0001, 0002, ...0010.. 0999, 1000

if there are 10,000 records I need to use 00001, 00002, ...00010.. 00999, 09999, 10000

So basically leading zeros needs to Len(Max(CardNo)) - Len(CardNo)

e.g.

Card No =1, Max CardNo = 1000. no of zeros is 4-1=3  -   Result = 0001

Card No =123, Max CardNo = 1000. no of zeros is 4-3=1 - Result = 0123

Card No =1000, Max CardNo = 1000. no of zeros is 4-4=0 - Result = 1000

Could someone point me right direction?

Thanks

Mark

##### 9 意見

###### Shotaro Ito

In Professional edition or above,

Create data source as VB Script Multiline, Have a VBScript

```L = Len(Format.NumberSerializedLabels)
Value = String(L-1,"0") & 1```
###### Legacy Poster

In Professional edition or above,

Create data source as VB Script Multiline, Have a VBScript

```L = Len(Format.NumberSerializedLabels)
Value = String(L-1,"0") & 1```

In Professional edition or above,

Create data source as VB Script Multiline, Have a VBScript

```L = Len(Format.NumberSerializedLabels)
Value = String(L-1,"0") & 1```

Thanks for reply. How is it getting the max value of the required field?

###### Legacy Poster

Format.NumberSerializedLabels automatically contains the number of records to be printed (which should be equal to your max value).

###### Legacy Poster

Format.NumberSerializedLabels automatically contains the number of records to be printed (which should be equal to your max value).

Thanks. unfortunately the numbering does not always start from 1, and can have gaps (e.g. 1-1,000 and 3,001-10,000), so this is 8,000 records, but max No is 10,000, so i need to get the max (10,000)

Thanks again for reply though. I'm sure it will come in handy

###### Legacy Poster

How/where do you get the record values from? I googled for Max() / Min() functions in VBS but apparently they don't exist so you would have to write corresponding functions yourself, provided there is no other way to get the max value...

###### Shotaro Ito

In BarTender 10.1 you have Print Job Filed data source and that can show number of total records. However that might have problem using with VB Script.

###### Legacy Poster

In BarTender 10.1 you have Print Job Filed data source and that can show number of total records. However that might have problem using with VB Script.

as I mentioned above:

Thanks. unfortunately the numbering does not always start from 1, and can have gaps (e.g. 1-1,000 and 3,001-10,000), so this is 8,000 records, but max No is 10,000, so i need to get the max (10,000)

Thanks again for reply though. I'm sure it will come in handy

No of records doesn't help. I need the MAX value of a field

###### Shotaro Ito

Oops. Pardon me I didn't catch the point. I would do that in database side, before giving to BarTender.

###### Legacy Poster

Oops. Pardon me I didn't catch the point. I would do that in database side, before giving to BarTender.

Unfortunately, that's not an option, the CSV is supplied by third party product, and they can;t change the format of the output