Hello,
I am need to field calculate sequential numbers starting with 033900000100191511. So, the numbering would be 033900000100191511, 033900000100191512, 033900000100191513 etc...
Can anyone help me with a python script for this?
With much appreciation,
Ana
Solved! Go to Solution.
Ok... that is an ugly one, since you are working with strings so the simplest thing is to increment from a know easy starting point and concatenate the string to it.
try these fixes
pstart = 511
return "033900000100191" + str(rec)
can't test it, so just select a few rows and try it and report back with a screen grab of the table if possible
What is the field type?
What do you have as a script so far?
Hi,
It is a String fieldThe script I found on the field calculator help:Parser:
Python
Expression:
autoIncrement()
Code Block:
rec=0
def autoIncrement():
global rec
pStart = 1 #adjust start value, if req'd
pInterval = 1 #adjust interval value, if req'd
if (rec == 0):
rec = pStart
else:
rec = rec + pInterval
return rec
Ok... that is an ugly one, since you are working with strings so the simplest thing is to increment from a know easy starting point and concatenate the string to it.
try these fixes
pstart = 511
return "033900000100191" + str(rec)
can't test it, so just select a few rows and try it and report back with a screen grab of the table if possible
Hi Dan,
I've been trying the code but haven't been successful yet. Either it needs something different or our network problems are interfering with the calculation. I have attached a screen shot showing the field calculator with the adjusted code you provided below:
you need to enable the code block check box and set your python parser to python.
you don't include the Code block line because what follows is the code block
in the Expression box, you put in autoIncrement() which is the name of the script you using
PS
check the documentation on using code blocks in the examples section
Dan,I think this expression will calculate wrong number if the records more than 489.
because it will add a new digit and the total digits for record will be 19 digit , but Ana Young want 18 digit.
So, you should to know the count of all records that Ana have, to write the expression.
Using a generator expression and string formatting, the number of records doesn't need to be known ahead of time:
Expression:
next(g)
Code Block:
def gen(x): while True: yield "{:0=18}".format(x) x+=1 g = gen(33900000100191511) #or replace with different starting number (not string of number)
Yes. using your expression ,Joshua. let us not need to know number of records.
Good job, Joshua.