Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
It would be helpful to identify which software are you using so people can answer this better. – RyanDalton Feb 16 '11 at 21:44
up vote 4 down vote accepted

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

share|improve this answer
Wolfodrade, That code did the trick. I had to modify it just a bit to get the labels to start at 1: Static cnt As Integer Dim startValue as Integer Dim result as Integer startValue = 0 cnt = cnt + 1 result = cnt + startValue Thanks Alot! – WRector Feb 16 '11 at 23:19
Good to hear! Sorry I thought you were starting at 192. Now, can you a) please comment on MY message, b)give a point, c) choose my answer as the 'selected', and d) delete your answer here? The answers are for answers, not comments :-) Thanks in advance – WolfOdrade Feb 16 '11 at 23:19

It looks like you are setting Y to a new value in each iteration of the loop, but not retrieving it until after the loop completes. Have you tried:

For Counter = 1 To 192
  Y = "Pipe - " & counter
  Pipe_ID = Y
 Next counter
share|improve this answer

"Pipe-" &RIGHT ("00"&result,2)

share|improve this answer

Maybe I don't understand the question, but I would just make a Label expression like this: "Pipe - " & [OBJECTID].

I think that it would work - and you would always get unique labels.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.