replace_field_values_interactive.sml

  Download

More scripts: Vector

Syntax Highlighing:

comments, key words, predefined symbols, class members & methods, functions & classes
            
# Prompts the user for an input Polygon Vector, the database table,
# the table's field, the field value to replace, and the new field value.
#
# It then searches the field and replaces every instance of the old
# field value.
#
# The assumed field type is a String
vector V;
class DBTABLEINFO dbtable; # class used to get the table info
PopupMessage("Select /litedata/sf_data/HAYWSOIL/hsoils");
GetInputVector(V);
 
string tableName$ = PopupString("Enter the table name:"); # ie Wildlife
 
dbtable = TableGetInfo(V.poly.(tableName$)); # gets the class for the table we specified
numeric numRecords = dbtable.NumRecords;
 
string fieldName$ = PopupString("Enter the field name:");   # ie Grasses_Legumes for hsoils
string oldName$ = PopupString("Enter the field value to replace:"); # ie Good
string newName$ = PopupString("Enter the new field value:");  # ie Better
numeric i;
for i = 1 to numRecords  # loop through records
{
	if(V.poly.Wildlife[@i].(fieldName$)$ == oldName$) # if fieldValue found
	{
		V.poly.Wildlife[@i].(fieldName$)$ = newName$; # store new Value
	}
}