4

From time to time, I have to use Visual Basic in Calculate Field.

As the code get bigger, the more complicated is to debug it. And ArcGIS (9.3) does not help as the error messages are, in the best cases, something like:

"A field name was not found or there were unbalanced quotation marks.
ERROR 999999: Error executing function.
Failed to execute (Calculate Field)."

It's not very informative, has an ambiguous reference to the type of error and does not say the line of the code where the error occurred.

Is there a better way to debug the code in ArcGIS?

Does anyone have strategies to share, or a parallel software or site to do it?

2
  • 1
    I have had some success prototyping complex VBA expressions as Excel macros and using its debugging facilities :-).
    – whuber
    Sep 7, 2012 at 17:56
  • 4
    I would suggest learning and using Python instead. That way you can write and debug your functions in PyScripter or another decent IDE and either import or copy/paste them into the field calculator. If you need to use ArcObjects then this approach gets more complicated, though you could use comtypes there.
    – blah238
    Sep 7, 2012 at 18:13

1 Answer 1

2

Since you are using version 9.3 you can use VBA for very complex scripts and the immediate window for complex single-line expressions. Just create a procedure or a function in VBA and instead of field values set up variables of the same data type and assign them representative dummy values. You can then run the function or step through it line by line and examine each value.

For simpler "one-line" expressions you can open VBA paste the expression into the immediate window and run it. You will also have to declare variables with dummy values but you can do that prior to running your expression directly in the immediate window. I would use this approach when concatenating values from several fields, using mid, instr, len, trim, etc.

1
  • Thanks you for your answer. That was what I need. The Obvious part that I was missing was the use of dummy values to properly test it. Sep 10, 2012 at 8:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.