Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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? (and thanks) Phil

share|improve this question
add comment

4 Answers 4

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.

share|improve this answer
2  
That would be a terribly silly bug on ESRI's part, if this works. White-space parsing issues shouldn't cause a syntax error. –  Michael Todd Nov 4 '10 at 20:39
2  
@Michael You would enjoy the Raster Calculator in ArcGIS 9.x, then: most operators required surrounding whitespace for the parser to succeed. "Silly" isn't the word for it... –  whuber Nov 5 '10 at 2:45
add comment

What version of ArcMap are you using? I am assuming it is 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.

share|improve this answer
    
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
add comment

Did you 'Validate' the expression? Does it pass? Is this an FGDB or a PGDB table? For FGDB 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)

share|improve this answer
1  
This is more appropriate as a comment. –  Derek Swingley Nov 4 '10 at 20:28
add comment

is the field you are calculating an integer field? :) obvious

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.