Zee
Zee

Reputation: 1890

Using vb.net, how can I use a class, which does not have a namespace?

I have a file called class.vb. In a separate project, I would like to utilize this class. However, class.vb doesn't use a namespace.

class.vb:

Imports System

Public Class MyClass
     Public Sub DoSomething()
          Console.WriteLine("Hello")
     End Sub
End Class

Attempting to illustrate what I would like to do:

Imports MyAlias = C:\whatever\class.vb

Public Class MyOtherClass
     Public Sub DoSomethingElse()
          MyAlias.MyClass.DoSomething()
     End Sub
End Class

If this is possible, what's wrong with doing this? Perhaps there are differences between how a normal namespace import works and the file import..

Upvotes: 0

Views: 659

Answers (1)

micbobo
micbobo

Reputation: 872

To utilize an already existing class you need to right click on the folder (or simply the project) you want to add your class in (from visual studio) and do Add Existing Item. Then browse your file explorer and select your class. Once done it should be included properly.

If the class uses other classes from your previous project make sure you include them aslo.

If there are still problems after that you could simply create an empty class and copy paste the content into it

Upvotes: 1

Related Questions