HOME | VBA is gone: Who cares? | HOME |
VBA was the customization environment in ArcGIS since the release of version 8.0 some 10 years ago. The users of ArcGIS desktop were able to quickly open the VBA Editor embedded in ArcGIS and write code that automates certain tasks or even create custom VBA applications embedded in the ArcGIS projects. Now with the release of ArcGIS 10.0 VBA is already not available for use within the Field Calculator. With the release of ArcGIS 10.1 VBA will be totally gone. So what are the alternatives?
We are not going to discuss here the advantages and disadvantages of each of the above. The main purpose of this article is to outline how to create a development environment similar to VBA with ArcGIS 10 that will allow easy transition to a VBA-less ArcGIS customization and our choice for this is .NET. The main reasons for this are:
To conclude this introduction lets just compare two code snippets illustrating the easiness of converting VBA code to VB.NET |
|
Sample VBA routine | The VBA code from the left copied and pasted in Microsoft Visual Studio-VB.NET project (NO CHANGES MADE). |
One can see that when pasting VBA code in Microsoft Visual Studio(VS) many of the syntax differences are fixed automatically and the code is almost the same. The only error in this case reported by VS is that it cannot find "ThisDocument" which in ArcGIS VBA Editor refers to the currently active ArcGIS document , which can be easily fixed (see below). | |
Getting started
Creating your development environment
|
|
|
In the Solution Explorer
you will see a VB module added with the name of your button.
Double click on it to open the code. Lets add to the On Click procedure a single message box. |
|
In the dialog go to
Commands, select the Add-In Controls category, find your
button and drag it to any toolbar. Close the dialog If you click on the new button, you should get your code executed. |
Now we have something very similar to the VBA environment we are so used to. We need to add a procedure that will do something useful, and when call the procedure from the button it will execute our code. Creating a custom procedure
|
We can see that some of the
interfaces used are not recognized and reported as errors.
To fix this we need to add some references to ArcObjects.
The easiest way to find out which library needs to
be referenced we can go to the ArcObjects developers help and
check the interfaces reported as "not defined".
For IFeature for example the library is ESRI.ArcGIS.Geodatabase, for IPolycurve - ESRI.ArcGIS.Geometry, etc. To add the needed references, right click on the solution ==> Add Reference. In the dialog select the .NET tab, then find and select the libraries required |
|
To make our life easier
(and typing less) we can import the libraries mentioned
above in our module Now the only error reported by Visual Basic is ThisDocument which in VBA was used to get hold of our current document. In ArcGIS 10 Add-ins targeting ArcMap we can replace this with My.ArcMap.Document Now our procedure is ready to run. We just need to call it from the button we created. To do that we will replace our "Hello World" in the OnClick procedure of the button with Call generalize() |
NOTES:
|
For any comments and enquiries contact: webmaster@ian-ko.com Esri and all Esri products mentioned are trademarks of Environmental Systems Research Institute, Inc. Copyright: Ianko Tchoukanski |