Hi,

I'm searching for an arcpy script or VBscript for the field calculator so I can populate a field with consecutive numbers represented by a constant length string. The consecutive numbers can come from the "FID" field.

Example:

000001

000002

...........

000011

...........

000345

I had a VBA script from Easycalculate who does the trick, but it doesn't work in ArcGis 10.

VBA script:

'rec_Number_ConstantLengthString.cal

'Author: Ianko Tchoukanski

'http://www.ian-ko.com

'=========================

Static rec As Long

Static j As Long

Dim lStart As Long

Dim lInterval As Long

Dim i As Integer

Dim iStringLength As Integer

Dim sID As String

'============================

'set the variables below

iStringLength = 7

lStart = 0

lInterval = 1

'============================

sID = ""

If (j = 0) Then

rec = lStart

Else

rec = rec + lInterval

End If

For i = 1 To iStringLength - Len(CStr(rec))

sID = sID & "0"

Next i

sID = sID & CStr(rec)

j = j + 1

Anybody any ideas?

I'm searching for an arcpy script or VBscript for the field calculator so I can populate a field with consecutive numbers represented by a constant length string. The consecutive numbers can come from the "FID" field.

Example:

000001

000002

...........

000011

...........

000345

I had a VBA script from Easycalculate who does the trick, but it doesn't work in ArcGis 10.

VBA script:

'rec_Number_ConstantLengthString.cal

'Author: Ianko Tchoukanski

'http://www.ian-ko.com

'=========================

Static rec As Long

Static j As Long

Dim lStart As Long

Dim lInterval As Long

Dim i As Integer

Dim iStringLength As Integer

Dim sID As String

'============================

'set the variables below

iStringLength = 7

lStart = 0

lInterval = 1

'============================

sID = ""

If (j = 0) Then

rec = lStart

Else

rec = rec + lInterval

End If

For i = 1 To iStringLength - Len(CStr(rec))

sID = sID & "0"

Next i

sID = sID & CStr(rec)

j = j + 1

Anybody any ideas?

This might sound a bit simplistic, but have you tried to create the numbers in excel and then just copy and paste into the attributes table? To get the numbers to display as 001 (for example) in excel just type the first number as '001 the apostrophe will ensure that the cell contents are displayed exactly as you type them and not converted to 1. Just drag down the cells from the first, and there you are!

I've just tried this and it worked fine for me.

Paul