Select to view content in your preferred language

If statement in Field Calculator

8441
6
Jump to solution
05-07-2013 07:25 AM
GregSullivan1
Emerging Contributor
Hello,

I am having problems with if statements in the Field calculator. This is my first time trying to code something in the field calculator. I am familiar with coding as I have used java and visual basic before. I created contours and I have a field that is set to 1 for all contours that are not an interval of 5 and set to 2 for all 5 foot contours. I have created another Field called Layer that I want to populate with a string for Minor and a different string for major contours. Can anyone help with this?
0 Kudos
1 Solution

Accepted Solutions
JakeSkinner
Esri Esteemed Contributor
You can achieve this using python.  Here is an example:

[ATTACH=CONFIG]24101[/ATTACH]

View solution in original post

0 Kudos
6 Replies
JakeSkinner
Esri Esteemed Contributor
Hi Greg,

What constitutes the Layer field to have the Minor string, and Major string?  If the other field is 1, should the Layer field have a value of 'Minor'??
0 Kudos
GregSullivan1
Emerging Contributor
Yes I am trying to set the Layer field to 'Minor' if the other field = 1 and set the layer field to 'Major' if the other field = 2
0 Kudos
JakeSkinner
Esri Esteemed Contributor
You can achieve this using python.  Here is an example:

[ATTACH=CONFIG]24101[/ATTACH]
0 Kudos
RichardFairhurst
MVP Honored Contributor
In VB Script you would do the following:

Parser: VB Script

Use Codeblock: checked

Codeblock:
If [Other_Field] = 1 Then
  Output = "Minor"
ElseIf [Other_Field] = 2 Then
  Output = "Major"
Else
  Output = [Layer] '  Use the existing value of the field being calculated so that it won't change.
End If


expression: Output
JohannaValente
New Contributor

I've been on a 2 hour search for the right code to do my basic If/Then Statement and yours was the only one that worked, thank you!!

0 Kudos
RichardFairhurst
MVP Honored Contributor

Johanna:

I am glad it helped.

0 Kudos