Field Calculator to (2 Fields)

1279
6
09-05-2016 09:55 PM
CarlosHernandez8
New Contributor II

HELP ME! PLEASE!

dim n
if ([CATEGORIA_IPD] = 'MEDIA') And ([IVR]= 'PARCIALMENTE TRANSFORMADO') Then
n = 20

end if

0 Kudos
6 Replies
JayantaPoddar
MVP Esteemed Contributor

First, you are using VB Script parser, not Python (you have shared in Python space).

Try Replacing And with &.

If that doesn't solve the issue, also replace 20 with "20"



Think Location
CarlosHernandez8
New Contributor II

How to do with Python?

0 Kudos
JayantaPoddar
MVP Esteemed Contributor

Did you try the above steps in VB script parser? Is it still throwing error message?



Think Location
0 Kudos
JayantaPoddar
MVP Esteemed Contributor

If it is not a mandate to do everything in Field Calculaor, you could also Select by Attributes.

Expression:

[CATEGORIA_IPD] = 'MEDIA' AND [IVR]= 'PARCIALMENTE TRANSFORMADO'

Once the records are selected, you could open Field Calculator for R_1 and define 20 as the value.



Think Location
DanPatterson_Retired
MVP Esteemed Contributor

You have not assigned a value to a field.  Is 'n' your new field?

syntactically it should be

python parser! NOT VB

def calculate(field1, field2):
    if (field1 = 'MEDIA') and (field2 = 'PARCIALMENTE TRANSFORMADO'):
        n = 20  # or '20'
    else:
        n = ?????  # what do you want? "" or something else
    return n‍‍‍‍‍

Expression box
def calculate(!CATEGORIA_IPD!, !IVR!)

you have to provide an option for the case where they are not equal to your queries.  Move on to python.  The function is the first 6 lines, and what goes into the expression box is line 9

DarrenWiens2
MVP Honored Contributor

The only thing completely wrong in your original example is that VBScript uses double quotes for strings, not single quotes (Python uses either). You also don't need to 'dim' in VBScript, that's a VBA thing. You will also get a warning if the function returns nothing, but you can click past that.

0 Kudos