Solved! Go to Solution.
Perhaps I should be using Python, but old habits die hard as I have more of a VB background...
At any rate, I'm trying to update a field in a table using the Calculate Field tool. After fighting numerous errors, I decided to simplify my function to a very simple routine to isolate the problem. In the screenshot, I'm just returning the value I'm passing in as an input value to save in the field. However, I get the following error:[INDENT]
General error executing calculator.[/INDENT]
[INDENT]ERROR 999999: Error executing function.[/INDENT]
[INDENT]Syntax error[/INDENT]
[INDENT]Failed to execute (Calculate Field).
[/INDENT]
Screenshot of Calculate Field setup:
[ATTACH=CONFIG]25886[/ATTACH]
I know that VB (VBScript) has certain limitations, such as not being able to explicitly declare datatypes for variables, so I don't think that's the problem here. It appears that the "shell" or setup of either the function itself (in the Code Block box) or the function call (in the Expression box) is wrong. Once I get past this error, I can put the real logic in the function.
Does anyone know what I might be doing wrong?
Thanks!
EDIT: Using ArcMap 10.1
Test = 28 ' Hard Coded Value Test = Test / [MyField] ' Field Value evaluated at runtime per each feature or row Test = Test + %Value% ' Model Builder Variable evaluated at runtime per each iteration or based on user input to the model For i = 0 to 3 ' For loop processes up to 4 times, breaking out of the loop as soon as Test has grown larger than 1000. Test = Test * 10 If Test > 1000 Then Exit For Next
Perhaps I should be using Python, but old habits die hard as I have more of a VB background..
Perhaps I should be using Python, but old habits die hard as I have more of a VB background...
At any rate, I'm trying to update a field in a table using the Calculate Field tool. After fighting numerous errors, I decided to simplify my function to a very simple routine to isolate the problem. In the screenshot, I'm just returning the value I'm passing in as an input value to save in the field. However, I get the following error:[INDENT]
General error executing calculator.[/INDENT]
[INDENT]ERROR 999999: Error executing function.[/INDENT]
[INDENT]Syntax error[/INDENT]
[INDENT]Failed to execute (Calculate Field).
[/INDENT]
Screenshot of Calculate Field setup:
[ATTACH=CONFIG]25886[/ATTACH]
I know that VB (VBScript) has certain limitations, such as not being able to explicitly declare datatypes for variables, so I don't think that's the problem here. It appears that the "shell" or setup of either the function itself (in the Code Block box) or the function call (in the Expression box) is wrong. Once I get past this error, I can put the real logic in the function.
Does anyone know what I might be doing wrong?
Thanks!
EDIT: Using ArcMap 10.1
Test = 28 ' Hard Coded Value Test = Test / [MyField] ' Field Value evaluated at runtime per each feature or row Test = Test + %Value% ' Model Builder Variable evaluated at runtime per each iteration or based on user input to the model For i = 0 to 3 ' For loop processes up to 4 times, breaking out of the loop as soon as Test has grown larger than 1000. Test = Test * 10 If Test > 1000 Then Exit For Next
The Field Calculator has disabled the Function, Sub, Execute, and probably some other similar keywords in its parser for VB Script (and I believe for VBA as well prior to 10.0), possibly for security reasons to protect against code insertion. As a result, it is impossible to build a recursive function within the Field Calculator using VB. So if that is where you are going, you can't do that. And in fact when you use VB with a codeblock, the Expression will only be used for an Output variable name, and is not used to pass any input to the codeblock (unlike Python).
...
(Note: At the users conference I was told by the person who writes the SQL parser that he has intentionally disabled standard SQL functions that can be used by hackers for code insertion, and causes the parser to return errors if those function are attempted, since the parser treats them as unrecognized requests. Where he has allowed SQL functionality that could lead to Code Insertion if unprotected, he has only permitted it with well structured SQL commands and must to do additional parsing and evaluation within the ESRI parser to prevent any code insertion attempt before passing the SQL to the underlying database. Field Calculator has to offer the same kinds of protection and Function, Sub, and Execute are probably deemed too open ended to allow.