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.

  • 1
    What is the error message you're getting in the Geoprocessing-Results window? Jun 30 '11 at 15:52

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]


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

end if

And include output variable in the Prelogic section.

  • 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. 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. 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. Jul 1 '11 at 0:40

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.

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

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.

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.