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?

  • It would be helpful to identify which software are you using so people can answer this better. Feb 16 '11 at 21:44

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

  • 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

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


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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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