Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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
add comment

4 Answers

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
add comment

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
add comment

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

share|improve this answer
add comment

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
add comment

Your Answer

 
discard

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.