GetObject() / CreateObject

Discussion in 'AutoCAD' started by Ken Hutson, Apr 22, 2004.

  1. Ken Hutson

    Ken Hutson Guest

    Hi Group,

    Thanks to all for your help in the past. Here are two more questions.

    1. If I begin a new VB6 application, I see that I can choose Standard EXE
    or ActiveX EXE (and others). If I choose ActiveX EXE does that mean that I
    can use GetObject() or CreateObject() from AutoCAD VBA (or any other ActiveX
    application for that matter) to create an instance of my VB6 application?

    2. When I compile to EXE my executable always says Project1.exe. How do
    I change this?

    Regards,
    Ken Hutson
    San ANtonio, TX
     
    Ken Hutson, Apr 22, 2004
    #1
  2. Ken Hutson

    Jean-Yves Guest

    Hi Ken ,

    1. Yes . You are right .

    2. You can change your project name by clicking on the "Project" drop-down
    menu and by clicking on "Project properties" menu .

    Regards ,

    Jean-Yves
     
    Jean-Yves, Apr 22, 2004
    #2
  3. Ken Hutson

    Ken Hutson Guest

    Thanks Jean-Yves
    Ken Hutson

     
    Ken Hutson, Apr 22, 2004
    #3
  4. Ken Hutson

    bcoward Guest

    Ken,

    Hope your having a good day. Maybe I can help with your questions.

    #2

    When you compile you are seeing the name of your project as defined in your project properties window. The only attribute you will see is Name. Enter what you want your project named. Once you do this you will see in your project window that the name Project1 has changed to your project name. If you don't see any of these "panes" do the following:

    From the view menu select Project Explorer or the hotkey Ctrl+R. From the same view menu you can also select properties window or hotkey F4.

    #1

    Stop - read your help files for CreateObject and GetObject.

    CreateObject is a function that creates and returns a reference to an ActiveX object. You really need to read up on this to understand what is meant by an ActiveX object.

    Lets take starting AutoCAD from a VB exe project.

    Start a new EXE project

    Place a command button on the form

    Double click on the command button you just placed on the form. This will place you in the command button click event.

    Remember VB6 or VB Classic as we call it is an example of an event driven language. This of course can be debated but I'm being as simple as possible so I won't expand in that direction.

    Within the Command_Click event place the following code:

    Dim MyAcadApp As AcadApplication

    On Error Resume Next

    ' This sets a reference to AutoCAD Application
    Set MyAcadApp = GetObject(, "AutoCAD.Application")

    ' If the is an error then AutoCAD is not running. If not running you want to CreateObject.

    If Err Then
    Err.Clear ' Clear the error if it exists

    Set MyAcadApp = CreateObject("Autocad.Application") ' This opens the existing running instance of AutoCAD

    ' In the next line your checking for some other error. If one exists take a look at the error via Err (read up)
    If Err Then
    MsgBox Err.Description
    ' You've some type of error so you might as well quit here and fix the problem

    Exit Sub

    End If ' Close the second (nested) If condition

    End If ' Close the first if condition

    ' If your this far then look at AutoCAD
    MyAcadApp.Visible = True

    End Sub


    As for your question regarding starting your VB6 exe I would probably use the FindExecute and ShellExecute API functions as one alternative.....but let's not go there right now.

    Best of luck to ya, hope this helps.

    Regards,

    Bob Coward
    CADS, Inc

    800-366-0946
     
    bcoward, Apr 23, 2004
    #4
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.