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?

asked Feb 16, 2011 at 21:42
1
  • It would be helpful to identify which software are you using so people can answer this better. Commented Feb 16, 2011 at 21:44

4 Answers 4

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

answered Feb 16, 2011 at 21:53
2
  • 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! Commented Feb 16, 2011 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 Commented Feb 16, 2011 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
answered Feb 16, 2011 at 22:00
0

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

answered Mar 29, 2011 at 8:26
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.

answered Mar 29, 2011 at 13:10

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.