migrating your vba applications to desktop add-ins · 2012. 7. 26. · technical workshops | esri...

36
Technical Workshops | Esri International User Conference San Diego, California Migrating your VBA applications to Desktop Add-ins John Hauck, Chris Fox July 26, 2012

Upload: others

Post on 07-Oct-2020

4 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Migrating your VBA applications to Desktop Add-ins · 2012. 7. 26. · Technical Workshops | Esri International User Conference San Diego, California Migrating your VBA applications

Technical Workshops |

Esri International User Conference San Diego, California

Migrating your VBA applications to Desktop Add-ins

John Hauck, Chris Fox

July 26, 2012

Page 2: Migrating your VBA applications to Desktop Add-ins · 2012. 7. 26. · Technical Workshops | Esri International User Conference San Diego, California Migrating your VBA applications

• What are add-ins? • Introduction to .NET and Visual Studio • Converting VBA Code

Agenda

Page 3: Migrating your VBA applications to Desktop Add-ins · 2012. 7. 26. · Technical Workshops | Esri International User Conference San Diego, California Migrating your VBA applications

What are Add-ins?

Page 4: Migrating your VBA applications to Desktop Add-ins · 2012. 7. 26. · Technical Workshops | Esri International User Conference San Diego, California Migrating your VBA applications

• New way to extend ArcGIS Desktop Applications - Collection of tools on a toolbar - Perform action in response to application event

• Easy to build, install, and share - No Component Object Model (COM) registration - Authored in .NET, Java, or Python (new at 10.1)

ArcGIS Desktop Add-Ins

Page 5: Migrating your VBA applications to Desktop Add-ins · 2012. 7. 26. · Technical Workshops | Esri International User Conference San Diego, California Migrating your VBA applications

• Buttons and Tools • Toolbars • Menus • Construction Tools • Tool Palettes • Combo Boxes • Multi-Items • Context Menus • Dockable Windows • Extensions

Supported Add-In Types

Page 6: Migrating your VBA applications to Desktop Add-ins · 2012. 7. 26. · Technical Workshops | Esri International User Conference San Diego, California Migrating your VBA applications

Add-in Wizard

Page 7: Migrating your VBA applications to Desktop Add-ins · 2012. 7. 26. · Technical Workshops | Esri International User Conference San Diego, California Migrating your VBA applications

Add-in Contents

Resources

Add-in file (.esriaddin) AAddddddddd-iiiiinnnn fffffffiiiiiiillllllleeeee

( i ddi )

Assemblies/ JARs XML

Metadata

Page 8: Migrating your VBA applications to Desktop Add-ins · 2012. 7. 26. · Technical Workshops | Esri International User Conference San Diego, California Migrating your VBA applications

• No registration required - Installed by copying to a well-known folder - Uninstalled by deleting

• Single file

- Upload to arcgis.com- Attach to e-mail - Place on network file share

Easy to Install and Share

Page 9: Migrating your VBA applications to Desktop Add-ins · 2012. 7. 26. · Technical Workshops | Esri International User Conference San Diego, California Migrating your VBA applications

• Add-ins built for previous version will load automatically in newer versions

- No need to rebuild or reinstall

• Add-ins are not backwards compatible

Compatibility with Newer Versions

Page 10: Migrating your VBA applications to Desktop Add-ins · 2012. 7. 26. · Technical Workshops | Esri International User Conference San Diego, California Migrating your VBA applications

Add-in Installation

Page 11: Migrating your VBA applications to Desktop Add-ins · 2012. 7. 26. · Technical Workshops | Esri International User Conference San Diego, California Migrating your VBA applications

Introduction to .NET and Visual Studio

Page 12: Migrating your VBA applications to Desktop Add-ins · 2012. 7. 26. · Technical Workshops | Esri International User Conference San Diego, California Migrating your VBA applications

• Development framework to build applications for the Windows Platform

• Key Features - Common Language Runtime - Interoperability - Base Class Library - Windows Forms

What is .NET?

Page 13: Migrating your VBA applications to Desktop Add-ins · 2012. 7. 26. · Technical Workshops | Esri International User Conference San Diego, California Migrating your VBA applications

• Coded solutions to common programming problems - Interacting with databases - Parsing XML - File reading and writing - String manipulation - Working with collections

Base Class Library

Page 14: Migrating your VBA applications to Desktop Add-ins · 2012. 7. 26. · Technical Workshops | Esri International User Conference San Diego, California Migrating your VBA applications

• Tools and Controls to build GUIs - Toolbars and Menus - Text Box, Combo Box, List View, Button - Layout and Data Binding

• Events driven

Windows Forms

Page 15: Migrating your VBA applications to Desktop Add-ins · 2012. 7. 26. · Technical Workshops | Esri International User Conference San Diego, California Migrating your VBA applications

• When building your add-in you need to target a specific version of .NET

• 3.5 is recommended for 10 and 10.1 - .NET 3.5 is required for ArcGIS Desktop

• 4.0 is supported at 10.1

Supported .NET Versions

Page 16: Migrating your VBA applications to Desktop Add-ins · 2012. 7. 26. · Technical Workshops | Esri International User Conference San Diego, California Migrating your VBA applications

• VB.NET - Syntax closest to VBA and VB6

• C# - Syntax similar to C++ & Java

• No difference in performance • Same access to .NET BCL and ArcObjects API

Selecting a Language

Page 17: Migrating your VBA applications to Desktop Add-ins · 2012. 7. 26. · Technical Workshops | Esri International User Conference San Diego, California Migrating your VBA applications

Where to write your code?

• Integrated Development Environment (IDE) - Source code editor - Debugger

• Visual Studio

- Visual Studio 2008 (10) and 2010 (10* and 10.1) - Free express version is supported

- *2010 VS Express not supported at 10.0

Page 18: Migrating your VBA applications to Desktop Add-ins · 2012. 7. 26. · Technical Workshops | Esri International User Conference San Diego, California Migrating your VBA applications

• One IDE for all .NET projects - Templates

• Code Editor - Syntax highlighting, code completion

• Debugger • Windows Forms Designer

- Drag/Drop controls

Visual Studio Features

Page 19: Migrating your VBA applications to Desktop Add-ins · 2012. 7. 26. · Technical Workshops | Esri International User Conference San Diego, California Migrating your VBA applications

• Project Templates and Wizards - Template for each Desktop Application - Add-in Wizard helps you declare components

• ArcGIS Snippet Finder - Code samples for common workflows

Esri’s Visual Studio integration

Page 20: Migrating your VBA applications to Desktop Add-ins · 2012. 7. 26. · Technical Workshops | Esri International User Conference San Diego, California Migrating your VBA applications

• Ensure the following are installed: - ArcGIS Desktop - Visual Studio - ArcObjects SDK for the Microsoft .NET Framework

- Order is important, VS before the SDK

Before you get started…

Page 21: Migrating your VBA applications to Desktop Add-ins · 2012. 7. 26. · Technical Workshops | Esri International User Conference San Diego, California Migrating your VBA applications

• Open Visual Studio and go to File > New Project

Creating a New Add-In Project

Page 22: Migrating your VBA applications to Desktop Add-ins · 2012. 7. 26. · Technical Workshops | Esri International User Conference San Diego, California Migrating your VBA applications

Define Information About Add-In

Page 23: Migrating your VBA applications to Desktop Add-ins · 2012. 7. 26. · Technical Workshops | Esri International User Conference San Diego, California Migrating your VBA applications

Define Add-In Components

Page 24: Migrating your VBA applications to Desktop Add-ins · 2012. 7. 26. · Technical Workshops | Esri International User Conference San Diego, California Migrating your VBA applications

Creating your Add-in

Page 25: Migrating your VBA applications to Desktop Add-ins · 2012. 7. 26. · Technical Workshops | Esri International User Conference San Diego, California Migrating your VBA applications

Converting VBA Code

Page 26: Migrating your VBA applications to Desktop Add-ins · 2012. 7. 26. · Technical Workshops | Esri International User Conference San Diego, California Migrating your VBA applications

• The business logic of your application is already written - No need to change the logic

• The ArcObjects interfaces and classes you work with are

the same in VBA and .NET

The hard part is already done

Page 27: Migrating your VBA applications to Desktop Add-ins · 2012. 7. 26. · Technical Workshops | Esri International User Conference San Diego, California Migrating your VBA applications

• VB.NET syntax is very similar - A lot of code will just work

• Some errors will be automatically fixed - SET keyword not used to instantiate variable

• Other errors will be highlighted for you

Copy/Paste VBA Code

Page 28: Migrating your VBA applications to Desktop Add-ins · 2012. 7. 26. · Technical Workshops | Esri International User Conference San Diego, California Migrating your VBA applications

• Add-In Wizard creates static classes depending on your type of customization.

- Entry point to Application and Document

• Replace references to ThisDocument and Application

- ex. My.ArcMap.Document, My.ArcMap.Application

Entry Points for Customization

Page 29: Migrating your VBA applications to Desktop Add-ins · 2012. 7. 26. · Technical Workshops | Esri International User Conference San Diego, California Migrating your VBA applications

• Unreferenced interfaces and classes are highlighted

• Right-Click Project > Add Reference > .NET tab - Find correct library from SDK help

• Use Imports to resolve name w/o being fully qualified - IMxDocument vs. ESRI.ArcGIS.ArcMapUI.IMxDocument

Add Namespace References

Page 30: Migrating your VBA applications to Desktop Add-ins · 2012. 7. 26. · Technical Workshops | Esri International User Conference San Diego, California Migrating your VBA applications

• Other common errors - Migrate Win32 API calls to .NET Framework libraries

- File I/O: CopyFile vs. System.IO.File.Copy - http://msdn.microsoft.com/en-us/library/aa302340.aspx

- Not all types are the same, key differences:

Resolve Remaining Errors

VBA VB.NET Variant/Object Object Currency Decimal Integer Short Long Integer

Page 31: Migrating your VBA applications to Desktop Add-ins · 2012. 7. 26. · Technical Workshops | Esri International User Conference San Diego, California Migrating your VBA applications

• Build > Build Solution - Need to resolve all errors before build will complete

• Creates .esriaddin file and installs it - Add-in file created in bin folder - This is the only file that needs to be distributed

Building Your Add-in

Add-in file (.esriaddin) AAddddddddd-iiiiinnnn fffffffiiiiiiillllllleeeee

( i ddi )

Page 32: Migrating your VBA applications to Desktop Add-ins · 2012. 7. 26. · Technical Workshops | Esri International User Conference San Diego, California Migrating your VBA applications

• Add Breakpoints to the code • Debug > Start Debugging

- Will launch the Desktop Application

• Interact with the add-in in the Application

Debugging

Page 33: Migrating your VBA applications to Desktop Add-ins · 2012. 7. 26. · Technical Workshops | Esri International User Conference San Diego, California Migrating your VBA applications

Building and Debugging

Page 34: Migrating your VBA applications to Desktop Add-ins · 2012. 7. 26. · Technical Workshops | Esri International User Conference San Diego, California Migrating your VBA applications

Steps to evaluate UC sessions

• My UC Homepage > “Evaluate Sessions”

• Choose session from planner OR

• Search for session

www.esri.com/ucsurveysessions

Page 35: Migrating your VBA applications to Desktop Add-ins · 2012. 7. 26. · Technical Workshops | Esri International User Conference San Diego, California Migrating your VBA applications

• Thank you for attending

• Have fun at UC2012

• Open for Questions

• Please fill out the evaluation:

www.esri.com/ucsessionsurveys

First Offering ID: 1033

Second Offering ID: 1034

Page 36: Migrating your VBA applications to Desktop Add-ins · 2012. 7. 26. · Technical Workshops | Esri International User Conference San Diego, California Migrating your VBA applications