I am currently running a large model and when I get to the part where there is a field calculation needed, it gives me this error. If I choose to continue running the model, it continues fine. It just seems to be at this part that the field calculation gets hung up. The problem occurs with the first row of data, which is no different from any of the other rows of data. Has anyone else ever had this issue?
Hi Zach,
Can you provide more information. For example, what is the expression you are using for the field calculation? Could you also provide the value(s) of the field(s) you are using in the expression?
The expression I am using goes as follows:
Dim n
if ([Summary_Statistics_2.SUM_DrainArea_SF]) > 299 then
n = "MAJOR"
end if
The Summary_Statistics_2.SUM_DrainArea_SF field is a double field type and the variable of n is a string field type. Based off of what number is in the Summary_Statistics_2.SUM_DrainArea_SF, the variable is populated with one of four choices, Major, Minor, Xconnect or Compliant. When the error pops up I can choose to continue to run the model, and if I do the rest of the rows get the field populated with data. It seems to only happen to the first row that the tool hits.
Thanks
I believe you're running into the error because your expression does not return anything for certain cases, where the value is <= 299. Add an 'else' statement to always return a value.
if ([Summary_Statistics_2.SUM_DrainArea_SF]) > 299 then
n = "MAJOR"
else
n = ""
end if
Dim is not necessary anymore with VB Script. You have to have an else clause to output a value when the condition you have written is not met. Every record has to have an output. So change the calculation to the following where you replace [OUTPUT_FIELD] with the actual name of the Output Field (so that whatever is already in the output field is not changed):
Parser: VB Script
Use Codeblock: checked
Pre-Logic Codeblock:
if ([Summary_Statistics_2.SUM_DrainArea_SF]) > 299 then
n = "MAJOR"
else
n = [OUTPUT_FIELD]
end if
Field expression: n
Within my model I have three sections of code. The second section overrides the first and the third section overrides the second. There is an else statement in the first section of code within the model. Here are the three sections of code, in order from 1 to 3.
Dim n
if (([SummaryStatistics.SUM_DrainArea_SF]) > 0 And ([SummaryStatistics.SUM_DrainArea_SF])) <= 299 then
n = "MINOR"
else n = "COMPLIANT"
end if
Dim n
if [Lat_Defects.ProposedWork] = "35" then
n = "XCONNECT"
end if
Dim n
if ([Summary_Statistics_2.SUM_DrainArea_SF]) > 299 then
n = "MAJOR"
end if
In between these code sections there are other things going on but there are no other field calculations. There are simple things like Add Joins and Remove Joins.
Thanks
Remove the Dim statements. If this is all one calcuation, they cause the n variable to be reset before each section so the first and second section calculations are destroyed and overridden even when the condition of clause 3 is not met. Dim is useless in VB script and not to be used ever. If these are separate calculations they all need an else clause.
I am still running 10.2 so does that statement hold true for removing the Dim statements? Also, doesn't the Dim declare what my variable is?
Dim was only useful when VBA was used in the field calculator prior to 10.0, since VBA has several types of variables that can be instantiated by the Dim clause. After 10.0 calculations use VB Script and there is only one type of variable, so just by assigning a variable a value it is given a variable name and type without using the Dim clause.
Ok I removed the Dim statements from the script and I am still hitting that error in the last section of code. It is saying that the Calculated Value is Invalid for the row with object id = 84 in this case.