Select to view content in your preferred language

IF Statements

913
5
Jump to solution
03-02-2023 01:25 PM
SLouq
by MVP Regular Contributor
MVP Regular Contributor

Hi all,

I am trying to populate a Text Field with a 'yes' or 'no' attribute based on the results of an IF Statement and am running into the Syntax error.

I have a field named 'MAJOR ST' in my street centerline table to create classes for my streets. This is the field I am basing the If statement off of. I have added a field to the table called CAR. This is the field I want to populate with 'yes' or 'no'. If the attribute in the MAJOR_ST field is empty, then CAR should be YES. If the attribute in the MAJOR_ST field is 'Farm', the CAR should be NO. This is the statement I came up with but is causing an Syntax error.

IF ([MAJOR_ST] = "") THEN
[CAR] = "YES"
ELSE IF
([MAJOR_ST] = 'Farm') THEN
[CAR] = "NO"
END IF

SLouq_0-1677792192415.png

Can someone help me with this? All I want to do is populate the CAR field with a Yes or No 

Thanks

0 Kudos
1 Solution

Accepted Solutions
DavidPike
MVP Frequent Contributor

expression = myExpression

 

Dim myExpression
([MAJOR_ST] = "Farm") THEN
...

View solution in original post

0 Kudos
5 Replies
KenBuja
MVP Esteemed Contributor

You have to use double quotes

([MAJOR_ST] = "Farm") THEN
0 Kudos
SLouq
by MVP Regular Contributor
MVP Regular Contributor

Should my Field type for CAR be Text? I tried your suggestion and it still bombed. Also is my Expression field correct?

Thanks

0 Kudos
DavidPike
MVP Frequent Contributor

expression = myExpression

 

Dim myExpression
([MAJOR_ST] = "Farm") THEN
...
0 Kudos
SLouq
by MVP Regular Contributor
MVP Regular Contributor

That worked! 

Thanks.

0 Kudos
KenBuja
MVP Esteemed Contributor

Change some things on your Field Calculator window.

Expression should be "output"

The Code Block should be

dim output
IF [MAJOR_ST] = "") THEN
  output = "YES"
ELSEIF [MAJOR_ST] = "Farm" THEN
  output = "NO"
END IF

 

0 Kudos