Ever wanted to write an If Then Else statement with a text output, but didn’t know how to format it in field calculator?
This blog shows a simple example of how to do it using VB Script in the Field Calculator.
Below is a fictitious situation that uses an If Then Else statement.
According to Wikipedia Large woody debris (LWD) are the logs, sticks, branches, and other wood that falls into streams and rivers. This debris can influence the flow and the shape of the stream channel.
Since Large Woody Debris are floating objects in the water they have the ability to move with the river. The database below wants to consider Large Woody Debris collected after today’s date as old. Today’s date for this example is 09/12/14.
To do this the Field Calculator for EditType field can be used.
If Then Else statement description: If Large Woody Debris has a date of 9/12/2014 it will be defined as “New”; otherwise define the Large Woody Debris as “Old”; and if the feature is not Large Woody Debris nor have a Date of 9/12/2014 it is defined as “New”.
The following script does this.
Pre-Logic Script Code:
if [Date] = “9/12/2014” then
x = “New”
elseif [EditorName] = “Large Woody Debris” then
x = “Old”
x = “New”
Below is an explanations for each line.
Line 1 – define the function
Type – dim x
if then statement; If the date is 9/12/2014 then the field calculator will define it as “New”
Line 2 Type – if [Date] = “9/12/2014” then
Line 3 Type – x = “New”
Elseif then statement; If it is not today’s date and it is Large Woody Debris then the field calculator will define it as “Old”
Line 4 Type – elseif [Feature] = “Large Woody Debris” then
Line 5 Type – x = “Old”
else statement; if it doesn’t have today’s date and isn’t Large Woody Debris then the field calculator will define it as “New”
Line 6 Type – else
Line 7 Type – x = “New”
End the Statement
Line 8 Type – end if
Call out the Reclass Function
Under Field Name =
This instance it was Edit Type =
Type – x