Home Image-Pro Automation (Macros, Apps, Reports)

How do I write a SUB in PROJECT A in such a way that it can be called by a SUB in PROJECT B?

All --

How do I write a SUB in PROJECT A in such a way that it can be called by a SUB in PROJECT B?

For instance . . . .

PROJECT A
    Sub MyRoutineA()

        Debug.print "Hello from PROJECT A!"

    End Sub

PROJECT B   
    Sub MyRoutineB()

        'Call the routine in PROJECT A to say HELLO
Call MyRoutineA

End Sub
I have tried DECLARING the SUB as PUBLIC but that does not seem to work.  I looked in the HELP FILES and the entries in the DECLARATION GROUP (shown below) did not seem to lead anywhere.

'#EditingCert, '#EncryptingCert, '#Language, '#Reference, '#Uses, '#ViewingCert, #Region...#End Region, Attribute, Class, Class Module, Code Module, Const, Declare, Delegate, Dim, Enum...End Enum, Event, Function...End Function, Imports, Module, Object Module, Option, Private, Property...End Property, Public, ReDim, Static, Structure...End Structure, Sub...End Sub, WithEvents.

Thanks.

-- Matt




Best Answers

  • Answer ✓
    Hi Matt,

    This can be done by adding a reference to Project A in Project B.

    Project ProjectB
        Optimizer On
        'Add references to other projects using ReferenceProject.
        ReferenceProject "ProjectA.ipp"

    Pierre
  • Answer ✓
    Matt,

    You also have to prefix your call to ProjectA, using syntax like ProjectA.Sub1.

    Pierre

Answers

  • Pierre --

    Thank you for the assistance.

    I have done as you suggested and added a
    	ReferenceProject 
    To the PROJECT file of PROJECT B.

    When I use the COMPLETE PATH to PROJECT B's IPP FILE (I guess because PROJECT A and PROJECT B are not in the same FOLDER / DIR) the LOAD on PROJECT B completeS with no errors.

    When I create a SUB in a MODULE in PROJECT B that references a SUB in PROJECT A, the WORKBENCH LOAD on PROJECT B displays an EXPECTING A VAR NAME.

    Is seems that that the SUB in a MODULE in PROJECT B cannot see a SUB in a MODULE in PROJECT A.

    I attempted to add a
    	ReferenceProject 
    with the COMPLETE PATH to the VB FILE for the MODULE holding the SUB in PROJECT A but WORKBENCH did not like it.

    Any suggestions?

    Thanks.

    -- Matt
  • Pierre --

    Thanks you very much for that additional information.

    That was the SECRET SAUCE that made it work.

    After a bit of "playing" it seems that:

    1) The
    	ReferenceProject 
    does not need a FULL PATH if PROJECT A and PROJECT B are in the same FOLDER / DIR.

    2) Routines PROJECT B can call the functions in PROJECT A even if PROJECT A is not in the MY PROJECTS SECTION of the PROJECT EXPLORER.

    Thanks again.

    -- Matt

    *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-

    *** EXECUTIVE SUMMARY ***

    To call a routine in PROJECT A from a routine in PROJECT B do the following:

    1) Add a REFERENCEPROJECT STATEMENT in the PROJECT SECTION of the IPP FILE for PROJECT B that references the IPP FILE for PROJECT A (see below)
        Project ProjectB
            Optimizer On
            'Add references to other projects using ReferenceProject
            ReferenceProject "ProjectA.ipp"
    End Project
    2) Use the FULL PATH to the IPP FILE for PROJECT A if the IPP FILE for PROJECT A is not in the same FOLDER / DIR as PROJECT B (see below)
        Project ProjectB
            Optimizer On
            'Add references to other projects using ReferenceProject.
            ReferenceProject "c:\Project A Folder\ProjectA.ipp"
    End Project
    2) Call the routine (Sub1) in PROJECT A from a routine (MyBTestSub) in PROJECT B by prefacing the ROUTINE NAME with the appropriate PROJECT NAME so
        Sub MyBTestSub ()
    ProjectA.Sub1
    End Sub
    so now a MyBTestSub run within PROJECT B will have the same effect as a Sub1 run within PROJECT A.
  • All --

    There seems to be some sort of flaw in the connections that have been built between my PROJECTS A and B and the solution above is missing something to make B able to call ROUTINES within A.

    I have two PROJECTS A and B and they are both in the same folder.

    PROJECT A has:
        SUB A1
    PROJECT B has:
        ReferenceProject "ProjectA.ipp" in the IPP FILE
        SUB B1 that calls SUB A1

    Here is SUB A1:
        Sub StageHello ()
    
            MsgBox "hello from STAGE"
    
        End Sub

    Here is SUB B1:
        Private Sub button_StageMove_Click(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles button_StageMove.Click
    
            Stage_V1A.Stage_App_V1A.stagehello()
    
        End Sub


    I can do a LOAD on both PROJECT A and PROJECT B with no errors.

    When I trigger SUB B1, I get the following error

       

    PROJECT B = SAA

    I tried adding a LOADMODULE for the VB FILE that holds the SUB A1 CODE and WORKBENCH did not like that.

    Any other suggestions?

    Thanks.

    -- Matt
  • All --

    Any thoughts on this?

    The next step seems to be actually merging PROJECT A and PROJECT B into a PROJECT C by using

        ADD EXISTING MODULE

    but I would like to keep A and B separate if possible.

    Thanks.

    -- Matt
  • Matt,

    Can you please post Project A and B as IPX files, we'll look into it.

    Pierre
  • Pierre --

    There is a NON-DISCLOSURE . . .

    Can I relay them to you in another way or could we perhaps WEBEX for a short meeting to resolve this?

    Thanks.

    -- Matt
  • Pierre --

    Would you be available for a short WEBEX to diagnose why my PROJECT A and PROJECT B will not communicate through the

        ReferenceProject "ProjectA.ipp" in the IPP FILE for PROJECT B

    Thanks.

    -- Matt



Sign In or Register to comment.