Migrating from VBA to .NET <br />Desktop Add-ins<br />Lesley Bross<br />Portland State Universitylbross@pdx.edu<br />March...
Project background<br />CSAR engaged in a multi-year agreement with the USDA-NRCS, National Weather and Climate Council (N...
More background<br />GIS Weasel’s last release was in 2003<br />The GIS Weasel is used to:<br />Prepare watershed GIS laye...
HRU Delineation phase began summer 2010</li></li></ul><li>Our conundrum<br />VBA is going away<br /> But we want to be abl...
What about .NET add-ins ?<br />Install as plug-in to ArcMap; No Windows installation required<br />Single file - simple to...
What about .NET add-ins ?<br />3)  .NET add-in Development framework  is robust and relatively easy-to-use<br />Wizards as...
Development environment<br />ArcMap 10.0 desktop client<br />Microsoft IDE (Integrated Development Environment)<br />Visua...
ArcObjects 10 SDK</li></ul>Available on ArcMap Install CD<br />May also want to install VBA support<br />
IDE Express vs. Pro - ArcGIS Templates<br />Packaging: Packaging for COM (.dll) deployment; Missing from Express but not n...
C# or VB .NET ?<br />Familiarity with Visual Basic from using VBA made VB .NET an easier transition<br />VB .NET provided ...
Converting VBA code to use in .NET<br />1) Export forms and code modules from inside the VBA editor. Forms cannot be conve...
Converting – step 2<br />2) Dust off an old copy of Visual Basic 6 and create a new project. Add your exported VBA files t...
Converting – step 3<br />3) Open the VB 6 project in Visual Basic 2008. The .NET version of VB will recognize the VB 6 pro...
Converting – step 4<br />4) Create a new Visual Basic 2008 ArcMap Add-In project per ESRI guidelines <br />
Converting – step 5<br />5) Recreate the forms from the VBA project. Note: using the same field names results in less work...
Converting – step 6<br />6) Copy and paste the code from the converted project to the new project. Clean up warnings and r...
Language differences<br />There are lots! (see references at end)<br />Application: Application -> My.ArcMap.Application<b...
Our solution<br />Leave BAGIS (phase 1) tools in VBA with their toolbar<br />Develop HRU delineation tools on a separate t...
Introducing HDGIS<br />
Unit Testing<br />
What is unit testing?<br />Testing individual pieces/modules of code (functions or subs)<br />Provide known inputs and che...
Using NUnit<br />Download/install .exe from the NUnit website<br />Create a project separate from ArcObjects project; No t...
NUnit organization<br />Testing subs are in separate module from code they are testing<br />Testing subs are stored in tes...
TextFixtureSetUp<br /><ul><li>Runs before tests are conducted; Initializes ArcMap</li></li></ul><li>A unit test<br />
TextFixtureTearDown<br /><ul><li>Runs when tests are complete; Shutdown ArcMap</li></li></ul><li>Successful test<br />
Failed tests<br />
References<br /><ul><li>Add-ins for ArcGIS Desktop 10http://blogs.esri.com/Dev/blogs/arcgisdesktop/archive/2010/05/05/Add_...
ArcGIS Visual Studio IDE Integration Framework for extending ArcObjects: http://help.arcgis.com/en/sdk/10.0/arcobjects_net...
GEOG 490/590: GIS Programming: http://web.pdx.edu/~jduh/courses/geog490w11/index.htm
Migrating VBA/VB6 ArcObjects Applications to .NET: http://proceedings.esri.com/library/userconf/devsummit08/papers/migrati...
Upcoming SlideShare
Loading in...5
×

Migrating from VBA to .NET Desktop Add-Ins

4,556

Published on

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
4,556
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
50
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Migrating from VBA to .NET Desktop Add-Ins

  1. 1. Migrating from VBA to .NET <br />Desktop Add-ins<br />Lesley Bross<br />Portland State Universitylbross@pdx.edu<br />March 29, 2011<br />
  2. 2. Project background<br />CSAR engaged in a multi-year agreement with the USDA-NRCS, National Weather and Climate Council (NWCC) to develop a spatial decision support system (SDSS)<br />The new SDSS is intended to replace the USGS GIS Weasel tool used by NWCC to improve water forecast accuracy<br />The project was funded by USDA-NRCS National Water and Climate Center <br />(CESU Agreement #: 68-7482-10-514)<br />
  3. 3. More background<br />GIS Weasel’s last release was in 2003<br />The GIS Weasel is used to:<br />Prepare watershed GIS layers for Areas Of Interest (AOI)<br />Delineate Hydrological Response Units (HRU)<br />Generate HRU physical parameters that are used in hydrological models to forecast water supply<br /><ul><li>Basin Analysis GIS (BAGIS) phase completed 2009-2010 (See Dr. Duh’s session tomorrow at 1:30p)
  4. 4. HRU Delineation phase began summer 2010</li></li></ul><li>Our conundrum<br />VBA is going away<br /> But we want to be able to use all that VBA code we just finished writing for the AOI definition phase …<br />Project requirements<br />Users are accustomed to using ArcMap in their workflow and wish to continue doing so<br />Solution is easy to share (e-mail an .mxt)<br />Installation cannot modify the Windows registry (security)<br />Simple development framework<br />
  5. 5. What about .NET add-ins ?<br />Install as plug-in to ArcMap; No Windows installation required<br />Single file - simple to distribute<br />E-mail attachment<br />Well-known folder (network location)<br />
  6. 6. What about .NET add-ins ?<br />3) .NET add-in Development framework is robust and relatively easy-to-use<br />Wizards assist with adding components<br />No need to write COM interfaces<br />Benefits of .NET development environment (Intellisense, debugging, unit testing)<br />Access to entire library of VB .NET form controls (DataGridView, Tooltip, etc.)<br />
  7. 7. Development environment<br />ArcMap 10.0 desktop client<br />Microsoft IDE (Integrated Development Environment)<br />Visual Basic 2008 Express (free)http://www.microsoft.com/express/downloads/<br />Visual Studio 2010 Professional (free for 90 days with registration)<br /><ul><li>.NET framework: installed by default with Microsoft IDE
  8. 8. ArcObjects 10 SDK</li></ul>Available on ArcMap Install CD<br />May also want to install VBA support<br />
  9. 9. IDE Express vs. Pro - ArcGIS Templates<br />Packaging: Packaging for COM (.dll) deployment; Missing from Express but not needed for add-ins<br />ArcGIS Snippet Finder doesn’t work as documented in Express<br />Screenshots in documentation aren’t quite the same in Express<br />Debugger configured manually in Express (ArcGIS templates can cover this)<br />
  10. 10. C# or VB .NET ?<br />Familiarity with Visual Basic from using VBA made VB .NET an easier transition<br />VB .NET provided a migration path for our existing VBA scripts<br />Industry trends towards C# - ESRI Dev Summit<br />
  11. 11. Converting VBA code to use in .NET<br />1) Export forms and code modules from inside the VBA editor. Forms cannot be converted but their associated code can be exported. <br />
  12. 12. Converting – step 2<br />2) Dust off an old copy of Visual Basic 6 and create a new project. Add your exported VBA files to this project. “Washing” the code through VB6 allows you to run the VB upgrade wizard.<br />
  13. 13. Converting – step 3<br />3) Open the VB 6 project in Visual Basic 2008. The .NET version of VB will recognize the VB 6 project and volunteer to upgrade it to Visual Basic 2008.<br />
  14. 14. Converting – step 4<br />4) Create a new Visual Basic 2008 ArcMap Add-In project per ESRI guidelines <br />
  15. 15. Converting – step 5<br />5) Recreate the forms from the VBA project. Note: using the same field names results in less work when migrating the code. The add-in framework supports both ESRI DockableWindow and Windows Form objects for the UI.<br />
  16. 16. Converting – step 6<br />6) Copy and paste the code from the converted project to the new project. Clean up warnings and review comments added by the conversion routine<br />
  17. 17. Language differences<br />There are lots! (see references at end)<br />Application: Application -> My.ArcMap.Application<br />Document: ThisDocument -> My.ArcMap.Document<br />Exception handling: On Error GoTo / On Error Resume Next ->Try Catch Finally and throwing exceptions<br />
  18. 18. Our solution<br />Leave BAGIS (phase 1) tools in VBA with their toolbar<br />Develop HRU delineation tools on a separate toolbar with VB .NET<br />Convert re-usable functions from VBA to VB .NET using aforementioned process<br />Forms were not converted<br />
  19. 19. Introducing HDGIS<br />
  20. 20. Unit Testing<br />
  21. 21. What is unit testing?<br />Testing individual pieces/modules of code (functions or subs)<br />Provide known inputs and check output for expected results; Replaces user interface<br />NUnit: open source testing framework for .NET; Integrates with VB Express/Visual Studio. It’s free!<br />
  22. 22. Using NUnit<br />Download/install .exe from the NUnit website<br />Create a project separate from ArcObjects project; No templates<br />Add nunit.framework to project assemblies<br />Set NUnit as debug application; You can step through code while running Nunit tests<br />NUnit debug configuration will vary depending on IDE<br />
  23. 23. NUnit organization<br />Testing subs are in separate module from code they are testing<br />Testing subs are stored in test folder<br />Test data may also live in test project<br />Test project separate from Add-In project<br />Code modules are copied from test project to Add-In project when are validated<br />No testing subs/data in Add-In project; No forms in test project <br />
  24. 24. TextFixtureSetUp<br /><ul><li>Runs before tests are conducted; Initializes ArcMap</li></li></ul><li>A unit test<br />
  25. 25. TextFixtureTearDown<br /><ul><li>Runs when tests are complete; Shutdown ArcMap</li></li></ul><li>Successful test<br />
  26. 26. Failed tests<br />
  27. 27. References<br /><ul><li>Add-ins for ArcGIS Desktop 10http://blogs.esri.com/Dev/blogs/arcgisdesktop/archive/2010/05/05/Add_2D00_ins-for-ArcGIS-Desktop-10.aspx
  28. 28. ArcGIS Visual Studio IDE Integration Framework for extending ArcObjects: http://help.arcgis.com/en/sdk/10.0/arcobjects_net/conceptualhelp/index.html#//00010000021w000000
  29. 29. GEOG 490/590: GIS Programming: http://web.pdx.edu/~jduh/courses/geog490w11/index.htm
  30. 30. Migrating VBA/VB6 ArcObjects Applications to .NET: http://proceedings.esri.com/library/userconf/devsummit08/papers/migrating_vba-vb6_arcobjects_applications_to_net.pdf</li></li></ul><li>References<br /><ul><li>Nunit:http://www.nunit.org/index.php?p=home
  31. 31. The GIS Weasel!!http://wwwbrr.cr.usgs.gov/projects/SW_MoWS/software/weasel_s/weasel.shtml
  32. 32. Walkthrough: Building custom UI elements using add-ins:http://help.arcgis.com/en/sdk/10.0/arcobjects_net/conceptualhelp/index.html#/Walkthrough_Building_custom_UI_elements_using_add_ins/0001000001ms000000/</li>
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×