ArcPy Calculate Field Codeblock Error using VB

564
4
Jump to solution
08-28-2023 08:38 AM
JosephPilkington1
New Contributor II

Getting an ExecuteError: ERROR 999999: Error executing function. 99.9% positive the error is in my code block. I know, I should use python, but we are keeping the script consistent with VB. For the life of me I cannot see what I am doing wrong. Probably a quotation thing. I have a real problem with that. Lol. Any help is forever appreciated.

# Feature Layer Variable:
TaxParcel_Layer = "TaxParcel_Layer"

# School District Codeblock Variable:

SCHOOLDISTCodeblock = """
Dim X
if ([TaxParcel_INT.SCHOOLDISTNO] = "0091") Then
X = "ALMA CENTER SCHOOL DISTRICT"
elseif ([TaxParcel_INT.SCHOOLDISTNO] = "0476") Then
X = "BLACK RIVER FALLS SCHOOL DISTRICT"
elseif ([TaxParcel_INT.SCHOOLDISTNO] = "0485") Then
X = "BLAIR-TAYLOR SCHOOL DISTRICT"
elseif ([TaxParcel_INT.SCHOOLDISTNO] = "2009") Then
X = "GALESVILLE-ETTRICK-TREMPEALEAU SCHOOL DISTRICT"
elseif ([TaxParcel_INT.SCHOOLDISTNO] = "3428") Then
X = "MELROSE-MINDORO SCHOOL DISTRICT"
elseif ([TaxParcel.SCHOOLDISTNO] = "4186") Then
X = "OSSEO-FAIRCHILD SCHOOL DISTRICT"
elseif ([TaxParcel_INT.SCHOOLDISTNO] = "4368") Then
X = "PITTSVILLE SCHOOL DISTRICT"
elseif ([TaxParcel_INT.SCHOOLDISTNO] = "5460") Then
X = "SPARTA AREA SCHOOL DISTRICT"
elseif ([TaxParcel_INT.SCHOOLDISTNO] = "5747") Then
X = "TOMAH AREA SCHOOL DISTRICT"
elseif ([TaxParcel_INT.SCHOOLDISTNO] = "6426") Then
X = "WHITEHALL SCHOOL DISTRICT"
end if"""

arcpy.CalculateField_management(TaxParcel_Layer, "SCHOOLDIST", "X", "VB", SCHOOLDISTCodeblock)

1 Solution

Accepted Solutions
DanPatterson
MVP Esteemed Contributor
def school(fld):
    """specify the field name as"""
    if (fld == "0091"):
        X = "ALMA CENTER SCHOOL DISTRICT"
    elif (fld == "0476"):
        X = "BLACK RIVER FALLS SCHOOL DISTRICT"
    elif (fld == "0485"):
        X = "BLAIR-TAYLOR SCHOOL DISTRICT"
    elif (fld =="2009"):
        X = "GALESVILLE-ETTRICK-TREMPEALEAU SCHOOL DISTRICT"
    elif (fld =="3428"):
        X = "MELROSE-MINDORO SCHOOL DISTRICT"
    elif (fld == "4186"):
        X = "OSSEO-FAIRCHILD SCHOOL DISTRICT"
    elif (fld == "4368"):
        X = "PITTSVILLE SCHOOL DISTRICT"
    elif (fld == "5460"):
        X = "SPARTA AREA SCHOOL DISTRICT"
    elif (fld == "5747"):
        X = "TOMAH AREA SCHOOL DISTRICT"
    elif (fld =="6426"):
        X = "WHITEHALL SCHOOL DISTRICT"
    else:
        X = "no clue"
    return X

you can begin with a more literal translation, although there are better data structures that could be used in the code block (eg a dictionary), but this should get you started


... sort of retired...

View solution in original post

0 Kudos
4 Replies
DanPatterson
MVP Esteemed Contributor

You have posted this in ArcGIS Pro place, hence, supported CalculateField languages include

Python, Arcade, SQL

Calculate Field (Data Management)—ArcGIS Pro | Documentation


... sort of retired...
0 Kudos
JosephPilkington1
New Contributor II

Any python3 scripting suggestions under this scenario?

0 Kudos
DanPatterson
MVP Esteemed Contributor
def school(fld):
    """specify the field name as"""
    if (fld == "0091"):
        X = "ALMA CENTER SCHOOL DISTRICT"
    elif (fld == "0476"):
        X = "BLACK RIVER FALLS SCHOOL DISTRICT"
    elif (fld == "0485"):
        X = "BLAIR-TAYLOR SCHOOL DISTRICT"
    elif (fld =="2009"):
        X = "GALESVILLE-ETTRICK-TREMPEALEAU SCHOOL DISTRICT"
    elif (fld =="3428"):
        X = "MELROSE-MINDORO SCHOOL DISTRICT"
    elif (fld == "4186"):
        X = "OSSEO-FAIRCHILD SCHOOL DISTRICT"
    elif (fld == "4368"):
        X = "PITTSVILLE SCHOOL DISTRICT"
    elif (fld == "5460"):
        X = "SPARTA AREA SCHOOL DISTRICT"
    elif (fld == "5747"):
        X = "TOMAH AREA SCHOOL DISTRICT"
    elif (fld =="6426"):
        X = "WHITEHALL SCHOOL DISTRICT"
    else:
        X = "no clue"
    return X

you can begin with a more literal translation, although there are better data structures that could be used in the code block (eg a dictionary), but this should get you started


... sort of retired...
0 Kudos
JosephPilkington1
New Contributor II

THANK YOU! Worked like a charm! 🙂

0 Kudos