The Field Calculator can be used to set the field value of one, several, or all the records in a table. The Field Calculator is a useful tool for copying, concatenating or creating new fields of information.
Components of Field Calculator
To open the Field Calculator, open an attribute table or other table in Christine. Click on the name of the field to be edited and select Calculate command. Second way is to select Calculate command from Field menu and then choosing the field to be edited. Note, that table must not be opened for read only access. To calculate on all records in a table, do not select any records or select all records. To calculate only on one or on several records select they before you will perform calculation.
One common use for the Field Calculator is copying the contents of one field to another field. With the Field Calculator open, click on a source field under the Field list. The field should appear in the Field Calculator workbox in brackets. Type semicolon and press Calculate button. This will populate the new field with a copy of the data in the source field. Of course, type of both fields must be the same, otherwise you must convert the data.
Into workbox of Field Calculator you can type more complicated calculations using Christine’s script language. For more information about it see Calculating a field’s values chapter in Christine’s help, or Change absolute paths in data source catalog to relative sample. Note that you can use Help button in Field Calculator to get description for method you want to use. Simply select typed method in Field Calculator workbox and press Help button.
Additional examples of operations that can be performed in Field Calculator are included in following tables.
|Add two (or more) fields||[NUMFLD] = [NUMFLD1] + [NUMFLD2];|
|Subtract two (or more) fields||[NUMFLD] = [NUMFLD1] - [NUMFLD2];|
|Multiply two (or more) fields||[NUMFLD] = [NUMFLD1] * [NUMFLD2];|
|Divide two (or more) fields||[NUMFLD] = [NUMFLD1] / [NUMFLD2];|
|Convert units from meters to feet||[NUMFLD] = [METERS_FLD] * 3.2808;|
|Convert degrees, minutes, seconds to decimal degrees||[NUMFLD] = [DEG] + ([MIN]/60) + ([SEC]/3600);|
|Calculate population density||[NUMFLD] = [TOTAL_POP] / [AREA];|
|Mean value of two fields||[NUMFLD] = ([NUMFLD1] + [NUMFLD2]) / 2;|
|Number of characters in string stored in text field||[TEXTFLD].GetLength([NUMFLD]);|
|Populate field with new text||[TEXTFLD] = "Text";|
|Concatenate two text fields without space||[TEXTFLD] = [TEXTFLD1] + [TEXTFLD2];|
|Concatenate two text fields with space||[TEXTFLD] = [TEXTFLD1] + " " + [TEXTFLD2];|
|Concatenate new text with space and field||[TEXTFLD] = "Text" + " " + [TEXTFLD1];|
|Write content of numeric field to text field||[NUMERICFLD].AsString([TEXTFLD]);|
|Write the leftmost n characters (where n is the number of characters)||[TEXTFLD].Left(n, [TEXTFLD]);|
|Write the rightmost n characters (where n is the number of characters)||[TEXTFLD].Right(n, [TEXTFLD]);|
|Convert all text to lowercase||[TEXTFLD].LCase();|
|Convert all text to uppercase||[TEXTFLD].UCase();|
|Trim space(s) from beginning and end of text||[TEXTFLD].TrimWhiteSpace(TRUE, TRUE);|
|Replace a character of text field by other (replaces “C” with “D”)||Number nLen i;
while(i < nLen);
if (sStr == "C");
i = i + 1;