3

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?

WRector
  • 85
  • 1
  • 5

4 Answers4

4

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
  • 2,748
  • 21
  • 24
  • 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
1

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
Regan Sarwas
  • 1,675
  • 11
  • 20
0

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

0

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.

Steen Kjeldsen
  • 841
  • 6
  • 7