Maksim,
I agree that this would be the least error prone method, but the OP is trying to work with AutoCAD 2002-2007. '02 & '04 don't have the capability to load managed extensions to AutoCAD. So that leaves COM interop.
moabiker31,
This is a complex issue. Ideally, you would create a different project for each version so you could reference the COM type libraries for each one. This also means that you need a new version for each service pack that comes out for each version. But the benefit that VB allows is turning Option Strict Off to allow late binding. This means that you also should remove the references to AutoCAD in the project. It also means you will lose intellisense, so do this last.
Alternately, you could use the TlbImp tool that comes with the .NET framework to generate Interop Libraries for all versions of AutoCAD, and give each set (AutoCAD TLB and ObjectDBX TLB) different namespaces
I.E.
AutoDesk.AutoCAD.200x.Interop for the AutoCAD.tlb where x is the version.
and
AutoDesk.AutoCAD.200x.Interop.Common for the AXDBLib.tlb, again where x is the version.
Then reference all of the generated Interop Libraries.
Next, create a class in your project for each version of AutoCAD you need to support.
Define an interface
Public Interface IAcadAutomation
Sub DoWork()
End Interface
Each class should look like so...
'Begin Class File
'x = the version of AutoCAD
Imports AutoDesk.AutoCAD.200x
Imports AutoDesk.AutoCAD.200x.Common
Public Class AutoCAD200x : Implements IAcadAutomation
Private mAcadApp As Autodesk.AutoCAD.200x.Interop.AcadApplication = Nothing
Public Sub New(ByVal AcadApp As Object)
m_Acadapp = directcast(acadApp , Autodesk.AutoCAD.200x.Interop.AcadApplication)
End Sub
Public Sub DoWork() Implements IAcadAutomation.DoWork
'Do the Work here
End Sub
End Class
'End Class File
and in ONE module, turn option strict off, load "AutoCAD.Application", check the version attribute and create an instance of the class that corrosponds with the version string returned. (just like the code i posted before)
You could put all your code that communicates with AutoCAD in the module that loads AutoCAD (Option Strict Off) and add a variable to each function which hold the autocad application as an object (late binding, no intellisense) OR you could but the code in each of the custon class modules (early binding, intellisense) but you will need to update all code in each class every time you make a change to one version.
There may also be a way to load the references of the current AutoCAD version when your App loads, but I don't have any experience there. I'm not even sure if the method I described above will work, but its a starting point.
Let us know how you make out,
C