Field Calculation - if statement (vbscript)

150
2
Jump to solution
03-16-2021 11:11 AM
eXoScoriae
New Contributor

I was trying to do something I thought would be fairly simply. I need to sort a bunch of dates into quarters. I started by created a new field with just the month of the dates. So, it is numbers 1 through 12 in a field that is defined as a string [Quarter]
I then created a blank strong field called Qtr. The idea is, to check the value in [Quarter] and assign either Q1, Q2, Q3, or Q4 to [Qty]

here is the code:
Pre-Logic Script Codeblock

Dim val
If [Quarter] = "1" then
val = "Q1"
else if [Quarter] = "2" Then
val ="Q1"
else if [Quarter] = "3" Then
val ="Q1"
else if [Quarter] = "4" Then
val ="Q2"
else if [Quarter] = "5" Then
val ="Q2"
else if [Quarter] = "6" Then
val ="Q2"
else if [Quarter] = "7" Then
val ="Q3"
else if [Quarter] = "8" Then
val ="Q3"
else if [Quarter] = "9" Then
val ="Q3"
else if [Quarter] = "10" Then
val ="Q4"
else if [Quarter] = "11" Then
val ="Q4"
else if [Quarter] = "12" Then
val ="Q4"
else
val = ""
end if


Code block
Qtr =

val

Seems really simply and straight forward. I've found plenty of other threads with similar if statements that seemed to work for the folks using them. 

The geoprocessor window is spitting out generic errors.
General error executing calculator
ERROR 999999: Error executing function
Expected 'If'
Failed to execute (CaluclateField)

0 Kudos
1 Solution

Accepted Solutions
DavidPike
MVP Frequent Contributor

is it not elseif rather than else if

View solution in original post

2 Replies
DavidPike
MVP Frequent Contributor

is it not elseif rather than else if

eXoScoriae
New Contributor

<face palm>

thank you