Declare a public variable within a Sub?

Discussion in 'AutoCAD' started by pkirill, May 20, 2004.

  1. pkirill

    pkirill Guest

    I'm working on this batch processor in VB6. Currently, you click a button and it opens a selected drawing in AutoCAD. The VB form stays open while you do some stuff in AutoCAD. My problem is that when you close AutoCAD, and try to run the processor again, you get "Runtime error '462': The remote server machine does not exist or is unavailable." I know this is because I have eliminated the AcadApplication by closing it.

    So, how can I perform a check to see if an instance of AutoCAD is available, if so assign it, and then if not recreate it?

    I tried resetting acad (Dim acad as New AcadApplication, and Dim dwg as AcadDocument) everytime the Proceed button is clicked, but I need the variable to be Public so I can accesses it from a second form.

    Any ideas would be great appreciated!
     
    pkirill, May 20, 2004
    #1
  2. pkirill

    Wayne Craig Guest

    My guess is that your problem stems from the variable declaration creating the "NEW" instance. If you instantiate the object this way and then somewhere set it to nothing in code, you can no longer recreate that object. For your case, it would be better to do something like:

    Dim acad as AcadApplication

    Then in the code do:

    Set acad = New AcadApplication

    This will let you zap acad to nothing (Set acad = Nothing) and then create a new instance (Set acad = New AcadApplication) whenever you need it again. It will also allow you to make acad a pubic variable. Hope that helps.

    Wayne
    I'm working on this batch processor in VB6. Currently, you click a button and it opens a selected drawing in AutoCAD. The VB form stays open while you do some stuff in AutoCAD. My problem is that when you close AutoCAD, and try to run the processor again, you get "Runtime error '462': The remote server machine does not exist or is unavailable." I know this is because I have eliminated the AcadApplication by closing it.

    So, how can I perform a check to see if an instance of AutoCAD is available, if so assign it, and then if not recreate it?

    I tried resetting acad (Dim acad as New AcadApplication, and Dim dwg as AcadDocument) everytime the Proceed button is clicked, but I need the variable to be Public so I can accesses it from a second form.

    Any ideas would be great appreciated!
     
    Wayne Craig, May 20, 2004
    #2
  3. pkirill

    pkirill Guest

    Wow - thanks guys! I think that's going to be just the ticket...
    My guess is that your problem stems from the variable declaration creating the "NEW" instance. If you instantiate the object this way and then somewhere set it to nothing in code, you can no longer recreate that object. For your case, it would be better to do something like:

    Dim acad as AcadApplication

    Then in the code do:

    Set acad = New AcadApplication

    This will let you zap acad to nothing (Set acad = Nothing) and then create a new instance (Set acad = New AcadApplication) whenever you need it again. It will also allow you to make acad a pubic variable. Hope that helps.

    Wayne
    I'm working on this batch processor in VB6. Currently, you click a button and it opens a selected drawing in AutoCAD. The VB form stays open while you do some stuff in AutoCAD. My problem is that when you close AutoCAD, and try to run the processor again, you get "Runtime error '462': The remote server machine does not exist or is unavailable." I know this is because I have eliminated the AcadApplication by closing it.

    So, how can I perform a check to see if an instance of AutoCAD is available, if so assign it, and then if not recreate it?

    I tried resetting acad (Dim acad as New AcadApplication, and Dim dwg as AcadDocument) everytime the Proceed button is clicked, but I need the variable to be Public so I can accesses it from a second form.

    Any ideas would be great appreciated!
     
    pkirill, May 20, 2004
    #3
  4. pkirill

    pkirill Guest

    Yup - worked beautifully!
    My guess is that your problem stems from the variable declaration creating the "NEW" instance. If you instantiate the object this way and then somewhere set it to nothing in code, you can no longer recreate that object. For your case, it would be better to do something like:

    Dim acad as AcadApplication

    Then in the code do:

    Set acad = New AcadApplication

    This will let you zap acad to nothing (Set acad = Nothing) and then create a new instance (Set acad = New AcadApplication) whenever you need it again. It will also allow you to make acad a pubic variable. Hope that helps.

    Wayne
    I'm working on this batch processor in VB6. Currently, you click a button and it opens a selected drawing in AutoCAD. The VB form stays open while you do some stuff in AutoCAD. My problem is that when you close AutoCAD, and try to run the processor again, you get "Runtime error '462': The remote server machine does not exist or is unavailable." I know this is because I have eliminated the AcadApplication by closing it.

    So, how can I perform a check to see if an instance of AutoCAD is available, if so assign it, and then if not recreate it?

    I tried resetting acad (Dim acad as New AcadApplication, and Dim dwg as AcadDocument) everytime the Proceed button is clicked, but I need the variable to be Public so I can accesses it from a second form.

    Any ideas would be great appreciated!
     
    pkirill, May 21, 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.