[GIS] VB Script case statment syntax for the field calculator in ArcGIS 10.2

arcgis-10.2arcgis-desktopfield-calculatorvbscript

Can anybody help me with this VB Script code for the field calculator in ArcGIS 10.2?
Why in the final result are all the values 10?

a= 10
Select Case UCase( [PRIORITY] )
 Case "AUX 1": a = 22.5
 Case "AUX2": a = 25
 Case "PRIMARY": a = 17.5
 Case "AUX 2": a = 25
 Case "AUX 3": a = 30
 Case "AUX 4": a = 32.5
 Case "NA" : a = 5
 Case "N/A": a = 5
 Case "SECONDARY": a = 15
 Case "SECONDARY2": a = 15
 Case "Tertiary": a = 10
 Case "MALL": a = 27.5
End Select

Best Answer

I would assume you're using this in the advanced field calculator (show codeblock)... In this case "Tertiary" would never be hit as you're getting the select case of the uppercase and that word contains lower case characters.

In this case a=10 at the start and none of the Case in the block are ever hit.

As to why none of these cases are ever hit depends on your data. As fatih_dir indicated you could have leading/trailing whitespace in your values, to try to overcome this use Trim:

a= 10
Select Case UCase(Trim([PRIORITY]))
 Case "AUX 1": a = 22.5
 Case "AUX2": a = 25
 Case "PRIMARY": a = 17.5
 Case "AUX 2": a = 25
 Case "AUX 3": a = 30
 Case "AUX 4": a = 32.5
 Case "NA" : a = 5
 Case "N/A": a = 5
 Case "SECONDARY": a = 15
 Case "SECONDARY2": a = 15
 Case "Tertiary": a = 10
 Case "MALL": a = 27.5
End Select

Note this will do nothing for Tab, Return etc.. again you can compensate for this by using Replace (I prefer to do it iteratively) vbTab, vbNewline with an empty string:

EmptyString = ""
CaseStr = UCase(Trim([PRIORITY]))
CaseStr = Replace(CaseStr,vbTab,EmptyString)
CaseStr = Replace(CaseStr,vbNewline,EmptyString)
Select Case CaseStr 
 Case "AUX 1": a = 22.5
 Case "AUX2": a = 25
 Case "PRIMARY": a = 17.5
 Case "AUX 2": a = 25
 Case "AUX 3": a = 30
 Case "AUX 4": a = 32.5
 Case "NA" : a = 5
 Case "N/A": a = 5
 Case "SECONDARY": a = 15
 Case "SECONDARY2": a = 15
 Case "Tertiary": a = 10
 Case "MALL": a = 27.5
End Select
Related Question