p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   VB.NET 2002/2003 Basics (http://p2p.wrox.com/forumdisplay.php?f=76)
-   -   Imports with .VB files (http://p2p.wrox.com/showthread.php?t=21020)

Doldrums November 9th, 2004 01:29 PM

Imports with .VB files
I am working with a project called "Portal" with a namespace of "Portal" at C:\Projects\Portal.

I also have some classes in a file at C:\Projects\Globals\MyCode.vb.

The MyCode.vb looks some like:

namespace "MyCompany.Globals"
public class Hello

  Shared public Function() As String
    Return "Hello World"
  End Function
End Class

End Namespace

How would I use the MyCompany.Globals.Hello class in the Portals project?

I've tried Imports MyCompany.Globals, but it says it can not find the namespace. Any help would be greatly appreciated!


katsarosj November 9th, 2004 02:58 PM

Compile your MyCode project into a .dll if you haven't already. Then add a reference to it by right-clicking on "References" in Solution Explorer. Browse for the .dll and add it. It should then be listed under your references.

You should then be able to access it.


Doldrums November 9th, 2004 03:41 PM

So you have to compile it? There is no way to link to source code that isn't under the project's directory structure unless it is compiled?

If so, that sucks. I still want this code to be compiled into my project... just want it located somewhere so multiple projects can use it.


katsarosj November 9th, 2004 04:32 PM


quote:Originally posted by Doldrums

just want it located somewhere so multiple projects can use it.

That's basically what you would be doing. The compiled .dll file can be referenced from as many projects as you want. Note that you compile it in it's own project and then reference it externally from whatever project you want.


planoie November 10th, 2004 10:01 AM


The .NET model is to use references to other assemblies. The .NET runtime cannot use source code, it must use the compiled result (assembly). Perhaps you need to create a project to contain your global code. The solution for one individual project can contain that global code project as well as the application specific project. This you can do with as many solutions as you wish.

Doldrums November 10th, 2004 10:56 AM

I guess I'm not making myself totally clear. [V]

I'm wanting to have my project use source code that is in a different directory and NOT in an assembly. Think of this as global code for all projects. I don't want this code to be in a separate DLL, I want it to be compiled into my current project's assembly.

I realize I can compile this code into a DLL, include it in my solution, and import it into my current project. That is not what I want to do. I want to have my VB project use .vb files that are located in a directory that is different that the current project's directory. I can't find a way to do this. Is it possible?

planoie November 11th, 2004 09:58 AM

No, not from what I know. Never actually tried it, but when you add a code file into a project the file lives in that project's directory. Are you using a source control system? Is so then I'll explain a technique to achieve what you want.

All times are GMT -4. The time now is 11:50 AM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.