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 am trying to do the following in the field calculator in ArcGIS 10

if  [IncdStDir] = " " then [IncdStNo] &" " & [IncdStName] &" " & [IncdStSfx]

else  [IncdStNo] &" " & [IncdStDir]&" " & [IncdStName] &" " & [IncdStSfx]

end if

I keep getting an error when I try to run this. I am new to Vb so any help would be appreciated.

share|improve this question
    
What is the error message you're getting in the Geoprocessing-Results window? –  Michael Todd Jun 30 '11 at 15:52
add comment

3 Answers

Updated code as @Russell Mercer suggested.

Make sure you have the advanced checkbox checked and are calculating on the field you want the result posted to. Try this:

Dim output

if  [IncdStDir] = " " then
output = [IncdStNo] & " " & [IncdStName] & " " & [IncdStSfx]

else 

output = [IncdStNo] & " " & [IncdStDir] & " " & [IncdStName] & " " & [IncdStSfx]

end if

And include output variable in the Prelogic section.

share|improve this answer
    
That did not work. I put the Dimo output as string in the Pre-logic section and then I copied your text in to the other section. Do I also have to put the Dim part in there as well? –  alicia Jun 30 '11 at 16:20
    
The parser in ArcMap is a little quirky at times. Try adding a space after all ampersands (so, & " " instead of &" ") to see if that helps. As long as all of those columns actually exist in the layer, nothing else looks wrong. –  Michael Todd Jun 30 '11 at 16:52
    
I have tried that and that did not work. –  alicia Jun 30 '11 at 17:00
    
@alicia Have you looked at the error message in Results? That might provide a hint in the right direction. –  Michael Todd Jun 30 '11 at 17:24
2  
@alicia - I just read today something about declaring variables using VBScript in ArcGIS 10. Variables are all declared as variant, so declaring a variable as "Dim output as string" will throw an error. The recommendation from the ESRI moderator was to change that to "Dim output" I don't have confirmation that this works, but your error matches the error others were reporting for the same circumstance. –  Get Spatial Jul 1 '11 at 0:40
show 1 more comment

Your Else clause doesn't have an = sign. You're not setting anything there, just concatenating fields. You need to set a value, call a function, or do something (technically you could leave the else clause blank, but that would be pointless). Just concatenating fields without setting a variable to them isn't a valid statement within the clause.

share|improve this answer
    
and by "= sign" you mean an assignment operator (as VB has overloaded this operator with equality) –  Mike T Aug 1 '11 at 19:45
add comment

You said you "put the Dimo output as string in the Pre-logic section and then I copied your text in to the other section". This is not correct for the field calculator.

Paste all of the code from "Dim output..." to "...End If" in the Pre-logic section. The only text in the other section should be output.

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.