DIM temp as String IF OBJECTID='1' THEN temp = 'Very Destructive' ELSEIF OBJECTID='2' THEN temp = 'Destructive' ELSEIF OBJECTID='3' THEN temp = 'Damaging' ENDIF
Dim temp If [OBJECTID] =1 Then temp = "Very Destructive" elseif [OBJECTID] = 2 Then temp = "Destructive" elseif [OBJECTID] =3 Then temp = "Damaging" else temp ="Nothing" end if
Excellent Chris, this works perfectly. Thanks very much.DKP.S. Any idea why elseif is one work but end if is two?
A couple things, VBScript does not allow you to explicitly declare any data types; all variables are implicitly Variant. Statements like Dim x as String should be removed or simplified to Dim x. If you want to execute only one statement when a condition is true, you can write the code on one line, otherwise each statement needs to be on a new line ieIf....Thenstatementelseif....Thenstatementelse statementend if Dim temp If [OBJECTID] =1 Then temp = "Very Destructive" elseif [OBJECTID] = 2 Then temp = "Destructive" elseif [OBJECTID] =3 Then temp = "Damaging" else temp ="Nothing" end if
Darrock,Did you also make the other changes I suggested not just the quotes?RegardsAnthonyP.S. not sure what version of arcmap your are using but I have just found this article:http://support.esri.com/en/knowledgebase/techarticles/detail/25207
Try using double speech marks around your text, and a space between your end and if on your last line, also the last else if only needs to be an else statement, plus the objectid field is numeric so you don't need the values in speech marks.DIM temp as StringIF [OBJECTID] = 1 THEN temp = "Very Destructive"ELSEIF [OBJECTID] = 2 THEN temp = "Destructive"ELSE [OBJECTID] = 3 THEN temp = "Damaging"END IF
Darroch, Field names need to be placed in brackets: DIM temp as String IF [OBJECTID]='1' THEN temp = 'Very Destructive' ELSEIF [OBJECTID]='2' THEN temp = 'Destructive' ELSEIF [OBJECTID]='3' THEN temp = 'Damaging' ENDIF Regards Anthony
General error executing calculator. ERROR 999999: Error executing function. Expected end of statement Failed to execute (CalculateField).
Signed in members can post, follow updates, and more. New here? Register a free account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.