Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Use code from another project 2

Status
Not open for further replies.

ESquared

Programmer
Dec 23, 2003
6,129
US
I thought I could load multiple projects in VB6 and use code from one project in another. But it appears that's not possible. I can create a project group with multiple projects showing and choose the startup project, but when I try to, say, declare a class variable of a class defined in the other project, intellisense is not working, telling me that it can't find the reference I'm trying to use.

Was I thinking of solutions as in VB .Net?

I know there are other options, such as:
- Include the code from the other project in the one I want to use it in
- Turn the project into a DLL and reference it in the other one

But I was hoping to keep my code modularized. I want to use a class in various projects that need the same functionality, without putting the code for that class into each project separately, so if I want to make a change I can do it in one place. I also want to keep this simple so there is no installation necessary, just a single .exe file to use. Adding a dll means I have to install and register it as well.

Any thoughts or ideas?
 
You could add the source code files to the project.

Ex:

Your main project could be located in:
C:\VB\MyApp

You could then have some shared source code located in:
C:\VB\SharedCode

You could then add the source code files to the app from the shared folder. I guess what I am trying to say is that a source code file can be included in multiple projects, not just one.

Open your app in VB.
Click Project -> Add Module (or Add Class module).
Browse to the folder with the source code and add it.

I think that I may not have explained this very well. Does this make sense?



-George

"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
First of all, have you set up the references between the projects?

For example, if project A is an EXE, and project B is a DLL, in order for A to use B's public objects, A must reference project B.

It is exactly the same as referencing a DLL, except you are referencing the Visual Basic Project (VBP) instead of the DLL. Check your references for project A, and see if it is referencing the VBP file for project B.

Secondly, does your project B expose public classes that your "client" project (A) can use? The "server" project (B) must have at least one class that the "client" project can instantiate and use. What this means is that project B must have at least one class whose Instancing property must be set to "5-MultiUse" or "6-GlobalMultiUse".

Finally, the only methods and properties of a project B class that can be accessed from project A are those that are declared as Public.

In other words, when one project references another project, the behaviour is exactly the same as if you had referenced the compiled version of the second project. A VB solution is not really a method for sharing common code, it is a way to build and test the different components of an n-tier application at the same.

If all you really want to do is share some common functions, then you can do what George suggests and store all your common modules in a separate location, and add each module as an "existing" item to any project where you would like to use it.


 
Now that you guys say all that, it makes perfect sense.

I figured out the vbp reference thing a couple of hours ago (just before going to lunch) but it's not the best for what I'm doing because it makes it difficult to edit the code.

Thanks for your input.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top