Тема: Проверка открыт ли Автокад в VB 6.0

Private Sub Form_Initialize()
Dim obj As Object
On Error Resume Next
Set obj = GetObject(, "AutoCAD.Application")
If obj Is Nothing Then
Unload Me
End If
End Sub
что то не правильно, а что ни как не пойму :(
подскажите пожалста
з.ы. и если не трудно подскажите как реализовать чтобы при выхода из автокада закрывалась и программа написаная на VB 6.0

Re: Проверка открыт ли Автокад в VB 6.0

проблема в том, что есть область жизни переменных, объектов...
у Вас
Dim obj As Object объявлен в Private Sub Form_Initialize()...
все отрабатывается и завершается при выходе из Private Sub Form_Initialize()...
поместите в модуль
Public obj As Object
и все заработает.

Re: Проверка открыт ли Автокад в VB 6.0

хелп в Автокаде просто супер - (читать надо...)
Connect to AutoCAD from Visual Basic 6
The following code example uses the Clear and Description properties of Err. If your coding environment does not support these properties, you will need to modify the example appropriately:
Sub Ch2_ConnectToAcad()
    Dim acadApp As AcadApplication
    On Error Resume Next
    Set acadApp = GetObject(, "AutoCAD.Application.16")
    If Err Then
        Err.Clear
        Set acadApp = CreateObject("AutoCAD.Application.16")
        If Err Then
            MsgBox Err.Description
            Exit Sub
        End If
    End If
    MsgBox "Now running " + acadApp.Name + _
           " version " + acadApp.Version
End Sub
Next, set the document variable to the Document object in the AutoCAD application. The Document object is returned by the ActiveDocument property of the Application object.
Dim acadDoc as AcadDocument
Set acadDoc = acadApp.ActiveDocument
From this point on, use the acadDoc variable to reference the current AutoCAD drawing.
а завершение работы проги надо повесить на событие в Автокаде
например(только событие поменяйте, из хелпа Автокада!)
EndOpen Example
Using Programming Languages other than VBA
Public WithEvents ACADApp As AcadApplication    ' Use with Application Event Examples
Sub Example_AcadApplication_Events()
    ' This example intializes the public variable (ACADApp) which will be used
    ' to intercept AcadApplication Events
    '
    ' The VBA WithEvents statement makes it possible to intercept an generic object
    ' with the events associated with that object.
    '
    ' Before you will be able to trigger any of the AcadApplication events,
    ' you will first need to run this procedure.
    ' We could get the application from the ThisDocument object, but that would
    ' require having a drawing open, so we grab it from the system.
    Set ACADApp = GetObject(, "AutoCAD.Application.16")
End Sub
Private Sub ACADApp_EndOpen(ByVal FileName As String)
    ' This example intercepts an Application EndOpen event.
    '
    ' This event is triggered when AutoCAD finishes opening a drawing.
    '
    ' To trigger this example event:
    '     1) Make sure to run the example that initializes
    '     the public variable (named ACADApp) linked to this event.
    '
    '     2) Use AutoCAD to open an existing drawing and wait until the
    '     operation finishes
    ' Use the "FileName" variable to determine which drawing file is being opened
    MsgBox "A drawing was just loaded from: " & FileName
End Sub
///----------------------------------------------------------
www.mechmagic.com

Re: Проверка открыт ли Автокад в VB 6.0

спасибки
усё получилось:)