It is currently Sun May 19, 2013 12:31 pm

All times are UTC





Post new topic Reply to topic  [ 8 posts ] 
Author Message
PostPosted: Fri Jun 17, 2011 11:30 am 
Offline
MCAD Lurker

Joined: 17 Jun 2011
Posts: 16
Country: Austria
State: Non US/CAN Resident
CAD System: Inventor
Hello together!

is it possible to run a Sub or Function vom a second IVB-File which is protected?

I can load the IVB File - but how do I get acces to public subs in this protected VBA-Project?

Many thanks in advance
Greetings


Share on FacebookShare on TwitterShare on DiggShare on DeliciousShare on TumblrShare on Google+
Top
 Profile  
 
PostPosted: Fri Jun 17, 2011 6:42 pm 
Offline
MCAD Addict
User avatar

Joined: 22 Mar 2004
Posts: 530
Country: United States
State: Pennsylvania
CAD System: Inventor
You'll have to reference the Project using the Tools/References dialog.

You should then see the Public Modules and/or Classes in the Object browser.

Usually, Shared functions/subs are encapsulated in a Class (Look in the Object Browser for the names). You will have to create an instance of the Class in your code to access its Methods/Properties etc. Usually something like this...

Dim clsTEST As New ImportedClassName

Best Regards,

_________________
Robert A. Williams
http://www.leacar.com
"Gentlemen...you can't fight here. This is the War Room!"


Top
 Profile  
 
PostPosted: Mon Jun 20, 2011 4:23 am 
Offline
MCAD Lurker

Joined: 17 Jun 2011
Posts: 16
Country: Austria
State: Non US/CAN Resident
CAD System: Inventor
Hello Robert,

thank you for your reply!

Ok - that sounds easy - but how do i handle the forms?

In my case i have several modules and one class in my IVB. Nearly every module launches a form. And one launches a form and dims a class.

Is it possible to do following?
Code:


Main IVB
|
|--SubIVB1 (protected)
|       |--Module1
|       |--Form1
|
|--SubIVB2 (protected)
|       |--Module2
|       |--Form2
|
|--SubIVB3 (protected)
        |--Module3
        |--Form3
        |--Class

Best Regards.

EDIT:
If i choose the IVB for reference, which is located on a network drive, i get an "Automation Error".
Any ideas what i've done wrong?


Top
 Profile  
 
PostPosted: Mon Jun 20, 2011 8:23 pm 
Offline
MCAD Addict
User avatar

Joined: 22 Mar 2004
Posts: 530
Country: United States
State: Pennsylvania
CAD System: Inventor
Hi "Lagsgh":

It's been awhile since I've worked in the VBA environment, but the only reason I can think of that would throw an "automation error" would be if there are no classes defined in the object you are referencing.

When you say "protected", do you mean a password-protected IVB file or something else altogether, like a compiled DLL?

Best Regards,
Robert

_________________
Robert A. Williams
http://www.leacar.com
"Gentlemen...you can't fight here. This is the War Room!"


Top
 Profile  
 
PostPosted: Tue Jun 21, 2011 4:40 am 
Offline
MCAD Lurker

Joined: 17 Jun 2011
Posts: 16
Country: Austria
State: Non US/CAN Resident
CAD System: Inventor
Hello Robert,

my IVB, i want to reference, contains one Module, one Class and one Form.

In the Module i have code like this:
Code:
Option Explicit

Public Sub init()
    Dim cl1 As New Class1
    cl1.NamePartNew
End Sub


Code of the Class:
Code:
Option Explicit

Public Sub NamePartNew()
    Form1.Show vbModeless
End Sub


The Form contains much more code.

I switched to my default.ivb and tried to reference this IVB - unfortunately i get an "Automation Error".

Can't find the failure. BTW I'm no professional programmer

Greetings
LAGSGH


Top
 Profile  
 
PostPosted: Tue Jun 21, 2011 2:28 pm 
Offline
MCAD Addict
User avatar

Joined: 22 Mar 2004
Posts: 530
Country: United States
State: Pennsylvania
CAD System: Inventor
LAGSGH:

I'm sorry as I mislead you in the previous post as I'd forgotten about the restrictions in VBA. When you use an External Project in VBA, the rules are different and very restrictive. You cannot directly instance a Class or Form from an externally referenced VBA Project.

It can be done but it is a little convoluted....

In the VBA Project to be referenced. If you have a Form "RAWForm" and a Class "RAWClass" that you want to instance in a second VBA Project. Put this code in a MODULE inside the VBA Project to be referenced.
Code:
Public Function InstanceRAWClass() As RAWClass
    Set InstanceRAWClass = New RAWClass
End Function

Public Function InstanceRAWForm() As RAWForm
    Set InstanceRAWForm = New RAWForm
End Function


In the VBA Project to be referenced, you must also set the Class [RAWClass] Instancing Property to "PublicNotCreatable"

In the VBA Project that is referencing the first VBA Project, Set a Reference as described in the earlier post to the first VBA Project. ("TestReferenceProject" in this example). Then you can access the Class and Form using this code...

Code:
Dim clsRAW As TestReferenceProject.RAWClass
Dim frmRAW As Object

    Set clsRAW = TestReferenceProject.InstanceRAWClass
    Set frmRAW = TestReferenceProject.InstanceRAWForm

    frmRAW.Show
   
    clsRAW.DivideByTwo 6


Best Regards,

_________________
Robert A. Williams
http://www.leacar.com
"Gentlemen...you can't fight here. This is the War Room!"


Top
 Profile  
 
PostPosted: Wed Aug 03, 2011 10:36 am 
Offline
MCAD Lurker

Joined: 17 Jun 2011
Posts: 16
Country: Austria
State: Non US/CAN Resident
CAD System: Inventor
Hello Robert,

sorry to answer your post so late - i was very busy in the last time.

I did all you recommended.

The Problem is that the IVB to be referenced must be loaded within VBA environment. If I only open the second project and then open the "References window" the first project ist displayed with the prefix "MISSING"

BG


Top
 Profile  
 
PostPosted: Thu Nov 10, 2011 9:11 am 
Offline
MCAD Lurker

Joined: 17 Jun 2011
Posts: 16
Country: Austria
State: Non US/CAN Resident
CAD System: Inventor
Hello Robert,

after putting this problem aside now i have reserved some time to continue with this test.

After starting the macro I get an other error saying following: "Compile Error: Expected End Sub".
The Macro stops right behind after teh "frmRAW.Show".

:?:

Hope you can help me with this an the older problem.
Thank you,
BR

LAGSGH wrote:
Hello Robert,

sorry to answer your post so late - i was very busy in the last time.

I did all you recommended.

The Problem is that the IVB to be referenced must be loaded within VBA environment. If I only open the second project and then open the "References window" the first project ist displayed with the prefix "MISSING"

BG


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
POWERED_BY