VBScript If/Then Statement – How to Use If/Then Statement in VBScript for ArcGIS Field Calculator

arcgis-desktopfield-calculatorvbscript

I am trying to do a simple (or so I thought) if/then statement in the ArcGIS field calculator.

I am trying to add the HydroCode field – hydologic soil codes – to an existing data set. I know what the code should be based on the "MUSYM" number. For example, "MUSYM" 1667 has the hydrologic soil code A. The "MUSYM" field is a number and the "HydroCode" field is text.

I vaguely remember doing if/then statements years ago when I more actively used GIS. I have tried simple If "MUSYM" = 1667 Then "HydroCode" = A Endif along with some other variations but none are working.

What am I missing?? All of the help I have found online deals with very complex coding, I can't find anything for such a simple statement. I also can't find anything with just basic operational instructions as far as where the operators should go/punctuation/etc.

enter image description here

Best Answer

Normally, I try to direct anyone using the Field Calculator to use Python. But to answer your question directly, you'll need something similar to this below. It's a basic pattern of if/elseif/end if.

(substitute your own values of course, I use 9999/Z just to show an elseif)

enter image description here

Note: You mention that MUSYM is a number, but the way the values in your table are aligned to the left makes me think it is stored as a text field. If so, try the below instead:

enter image description here

Related Question