Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Declare a public variable within a Sub?

103 views
Skip to first unread message

pkirill

unread,
May 20, 2004, 11:59:18 AM5/20/04
to
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

unread,
May 20, 2004, 4:42:41 PM5/20/04
to
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
"pkirill" <pki...@NOSPAMkdcad.com> wrote in message news:40acd58e$1_3@newsprd01...

pkirill

unread,
May 20, 2004, 5:18:31 PM5/20/04
to
Wow - thanks guys! I think that's going to be just the ticket...
"Wayne Craig" <wcraig...@austin.rr.com> wrote in message news:40ad1847_2@newsprd01...

pkirill

unread,
May 21, 2004, 9:05:19 AM5/21/04
to
Yup - worked beautifully!
"Wayne Craig" <wcraig...@austin.rr.com> wrote in message news:40ad1847_2@newsprd01...

davi...@netzero.com

unread,
Aug 21, 2013, 7:07:15 AM8/21/13
to
ThankS. I was having a lot of problems with this!
0 new messages