Advancing switching interfaces from VB6 to VB.NET


Summary
This topic teaches ArcGIS developers how to take advantage of the .NET Framework best practices for switching interfaces when advancing their custom applications from Visual Basic 6 (VB6) to Visual Basic .NET (VB .NET).

About advancing switching interfaces from VB6 to VB .NET

In VB6, switching interfaces is performed using the concept of query interface (QI). Essentially, one interface is assigned to another interface via a Set statement. In VB .NET, the term QI is replaced with the term Casting. As of the .NET Framework 3.5, VB .NET offers four different Casting methods, each with its own merits.
The Microsoft Developer Network (MSDN) Visual Basic language reference topic, DirectCast, provides a starting point that ArcGIS developers will want to investigate in their ArcObjects development.
  • The following code example shows a VB6 QI scenario:
Dim areaPolygon as IArea 
Set areaPolygon = New Polygon
Dim geometry as Igeometry

'Query interface (QI).
Set geometry = areaPolygon
  • The following code example shows using the four Casting methods in VB .NET:
[VB.NET]
Dim areaPolygon As IArea = New PolygonClass

' Analogous to QI in VB6. Throws InvalidCastException on error.
Dim geoPolygon1 As IGeometry = areaPolygon

' Two other options that Throw InvalidCastException on errors.
Dim geoPolygon2 As IGeometry = CType(areaPolygon, IGeometry)
Dim geoPolygon3 As IGeometry = DirectCast(areaPolygon, IGeometry)

Returns Nothing On Error.
Dim geoPolygon4 As IGeometry = TryCast(areaPolygon, IGeometry)


See Also:

Migrating from VB6 to VB.NET
General steps for migrating from VB6 to VB.NET




Development licensing Deployment licensing
ArcGIS for Desktop Basic ArcGIS for Desktop Basic
ArcGIS for Desktop Standard ArcGIS for Desktop Standard
ArcGIS for Desktop Advanced ArcGIS for Desktop Advanced
Engine Developer Kit Engine