[GIS] VBA script for Incremental labeling in Field Calculator

vba

I have a shape file with a bunch of pipes in it. I would like to be able to label each pipe with "Pipe – X". X being the number in the row that the pipe falls on (Pipe – 1, Pipe – 2, Pipe – 3, etc).

I've tried using a for loop VBA Script for this but it doesn't work. The VBA script is as follows:

For counter = 1 To 192
Y = "Pipe – " & counter
Next counter

Pipe_ID = Y

My result is "Pipe – 192"

Any Ideas?

Best Answer

Use a static variable to keep track of the incremental value (assuming you're using ArcGIS) in thei field calculator (toggle on the 'advanced' tab)


Static cnt As Integer
Dim startValue as Integer
Dim result as Integer
startValue = 192
cnt = cnt + 1
result = cnt + startValue

then, whateveryourfieldnameis="Pipe-" & result

I think that should work