5

I can't get the syntax correct for a fairly simple if statement. Right now it looks like this:

dim Output as Integer
If [HECTARES] >= 30 AND [HEIGHT] >= 17 AND [CROWN] >= 59
 THEN Output = 1
 ELSE Output = 0
END IF

I have no idea whether that's the correct use of "AND" but the expression wouldn't evaluate with only one expression (i.e. [HECTARES] > 30) either.

Thoughts?

6

Try this under the Field Calculator advanced option.

Dim Output as Integer 
If [HECTARES] >= 30 AND [HEIGHT] >= 17 AND [CROWN] >= 59  Then
Output = 1

else
Output = 0 
end if

I've gotten this syntax to work with my data.

4

I am assuming that you are using ArcGIS 10 and not 9.x.

According to the Calculate Field help file, in ArcGIS 10:

VBScript does not allow you explicitly declare any data types; all variables are implicitly Variant. Statements like Dim x as String should be removed or simplified to Dim x.

This worked for me in Arc 10:

Prelogic:

Dim output
IF [HECTARES] >= 30 and [HEIGHT] >= 17 and [CROWN] >= 59 THEN
Output = 1
ELSE
OUTPUT = 0
END IF

Field =

output

Basically, just remove "as Integer" and it will actually work on 9.3 as well.

  • Thanks Jason (and everyone else). Your version of the expression works fine. Though oddly the problem doesn't seem to be the explicit declaration of the data type as you code also works if I add in "as integer". The problem appears to be my expression parsing (e.g. using "Then Output = 1" rather than – Phil Greyson Nov 5 '10 at 11:53
  • My comment got timed out, hence the second part. I didn't have carriage returns in the correct places. Thanks again everyone. – Phil Greyson Nov 5 '10 at 11:55
1

Assuming that this is in a file geodatabase, enclose the field in "" - double quotes, for shapefile i think it's also double quotes. Each uses different "field" enclosure. If the expression passes validation, check for Null values. Also make sure the field is numeric (as was already mentioned)

  • 2
    This is more appropriate as a comment. – Derek Swingley Nov 4 '10 at 20:28

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.