26
Presenter: Sally Swenson ESRI Redlands, California Migrating to VB .NET

Ws vbnet slides

Embed Size (px)

Citation preview

Page 1: Ws vbnet slides

The presentation will begin at 9AM Pacific Time

Presenter: Sally Swenson ESRI Redlands, California

Migrating to VB .NET

Page 2: Ws vbnet slides

Seminar overviewTopics include

Moving from VB6 to VB .NETResolving tricky VB .NET issuesDistributing a VB .NET application

FormatEach topic followed by review and question and answer periodPresentation includes software demonstrations

Copyright © 2003 ESRI. All rights reserved.

Page 3: Ws vbnet slides

Moving from VB6 to VB .NET

Copyright © 2003 ESRI. All rights reserved.

Page 4: Ws vbnet slides

Reasons for migratingApplication requirements

Language options (VB and C#)Development environment

Built-in APIIntegrated HelpFully object oriented

Can't buy VB6 off the shelfVB6 is still available.ESRI Technical Article 24963 (http://support.esri.com)

ESRI requires migration to VB .NET?

Copyright © 2003 ESRI. All rights reserved.

Page 5: Ws vbnet slides

Reasons for migratingApplication requirements

Language options (VB and C#)Development environment

Built-in APIIntegrated HelpFully object oriented

Can't buy VB6 off the shelfVB6 is still available.ESRI Technical Article 24963 (http://support.esri.com)

ESRI requires migration to VB .NET? No, ESRI does NOT require VB .NETSupports VB6, or any language that supports COM

Copyright © 2003 ESRI. All rights reserved.

Page 6: Ws vbnet slides

More reasons for migrating Advanced features

ArcWeb ServicesDebugging

Beyond ICommand and IToolNew controls

DockingAnchoring

Copyright © 2003 ESRI. All rights reserved.

Page 7: Ws vbnet slides

Installing ArcGIS and VB .NETVisual Studio .NET 2002 or 2003

VB .NET onlyC++ and C#, if needed

ESRI ArcObjects .NET Developer KitContains API for ArcObjects development

Copyright © 2003 ESRI. All rights reserved.

Page 8: Ws vbnet slides

Adding assemblies...\ArcObjects Developer Kit\Dotnet\AssembliesESRI.ArcObjects.Core

DirectivesImports ESRI.ArcObjectsesriCore.IFeatureLayer > Core.IFeatureLayer

Getting started

Object Libraries (VB6) Assemblies (VB .NET)esriCore.olb Core

esriMx.olb Mx

esriSpatialExt.olb SpatialExt

esriStreetMap.olb StreetMapExt

esriSurveyCoreExt.olb SurveyCoreExt

Copyright © 2003 ESRI. All rights reserved.

Page 9: Ws vbnet slides

Using the ESRI Add-InsESRI Interface Implementer

Stubs out the implementation code wrapper linesNot needed for Visual Studio .NET 2003

ESRI Component Category RegistrarWorks with ESRI.ArcObjects.Samples.CatIDS assemblyAutomates component category registration

Copyright © 2003 ESRI. All rights reserved.

Page 10: Ws vbnet slides

Software demonstration

Copyright © 2003 ESRI. All rights reserved.

Page 11: Ws vbnet slides

Topic review and Q & AWhy migrate to VB .NET?InstallationAssemblies and DirectivesESRI Add-InsCreating projects in VB .NET

Copyright © 2003 ESRI. All rights reserved.

Page 12: Ws vbnet slides

Resolving tricky.NET issues

Copyright © 2003 ESRI. All rights reserved.

Page 13: Ws vbnet slides

Option statementsOption Explicit

On, by default Option Strict

Off, by defaultAllows narrowing conversion

On, recommendedPrevents narrowing conversionType safety

Copyright © 2003 ESRI. All rights reserved.

Page 14: Ws vbnet slides

Option Strict: query interface

Option Strict On Query Interface for ILayer

Option Strict Off Query Interface for ILayer

! Option Strict On disallows implicit conversions from 'ILayer' to 'IFeatureLayer'

featlayer = _CType(doc.focusmap.layer(0), IFeatureLayer)

Solution: Type cast

featlayer = doc.focusmap.layer(0)

Copyright © 2003 ESRI. All rights reserved.

Page 15: Ws vbnet slides

Exception handlingReplaces VB6 error handlingIf omit, beware!

Embedded resource is case sensitiveIf error, no warning plus no icon on interface

AssemblySystem.Runtime.InteropServices

TryGetManifestResourceStream("prj.zoomin.bmp")

Catch ex As ExceptionMsgBox _(ex.Message & "Error: " & [GetType]().Name)

Finally' Code you put in Finally will always execute

End Try

Copyright © 2003 ESRI. All rights reserved.

Page 16: Ws vbnet slides

Object by defaultIn VB6: multiple one-line declarations of same data type

In VB .NET, multiple one-line declarations of same data type

No more Variant

Dim i, j, k As Integer

Dim i, j, k As Integer

i = 11 ' Integerj = 12 ' Variantk = 13 ' Variant

i = 11 ' Integerj = 12 ' Integerk = 13 ' Integer

Copyright © 2003 ESRI. All rights reserved.

Page 17: Ws vbnet slides

Garbage collectionIn COM, need to free memory

In VB .NET, garbage collection is indeterminateobj = Nothing

Add the namespace

Release memory in the method that uses obj

Always release in a loop until ival = 0Dim ival As IntegerDo Until ival = 0ival = Marshal.ReleaseComObject(obj)

Loop

Imports System.Runtime.InteropServices

Marshal.ReleaseComObject(obj)

Copyright © 2003 ESRI. All rights reserved.

Page 18: Ws vbnet slides

Summary of changes with VB .NET

Visual Basic 6 Visual Basic .NETSet pAMap = pMxDoc.FocusMap AMap = MxDoc.FocusMap

Option Explicit Option Strict

DLL Assembly

Class module COM class

GUID created at compile GUID created in code

Error handling Exception handling

Debug.Print Debug.WriteLine

Class_Initialize / Terminate Class Constructor / Destructor

Copyright © 2003 ESRI. All rights reserved.

Page 19: Ws vbnet slides

Software demonstration

Copyright © 2003 ESRI. All rights reserved.

Page 20: Ws vbnet slides

Topic review and Q & AOption StrictException handlingGarbage collectionChanges with VB .NET

Copyright © 2003 ESRI. All rights reserved.

Page 21: Ws vbnet slides

Distributing an application

Copyright © 2003 ESRI. All rights reserved.

Page 22: Ws vbnet slides

Client requirements Full installation of ArcGIS

Including licenseArcObjects .NET Developer Kit

Assemblies

Copyright © 2003 ESRI. All rights reserved.

Page 23: Ws vbnet slides

Client requirements Full installation of ArcGIS

Including licenseArcObjects .NET Developer Kit

AssembliesVB .NET Framework (~500MB)

Already installed on newer machines

Copyright © 2003 ESRI. All rights reserved.

Page 24: Ws vbnet slides

COM component requirementsWindows registration

VB .NET Setup and Deployment wizard handles registrationAlternative: regasm.exe

Copyright © 2003 ESRI. All rights reserved.

Page 25: Ws vbnet slides

Topic review and Q & AClient requirementsCOM component requirements

Copyright © 2003 ESRI. All rights reserved.

Page 26: Ws vbnet slides

For more information

ArcObjects Onlinehttp://arcobjectsonline.esri.com

Getting Started >The .NET Framework

ESRI Instructor TrainingAdvanced ArcObjects Component Development I (VB)

Advanced ArcObjects Comp Dev II (.NET)

ESRI PressGetting to Know ArcObjects: Programming ArcGIS with VBA

Microsoftmsdn.microsoft.com/vbasic

Copyright © 2003 ESRI. All rights reserved.