Using functions between projects

  • Thread starter Thread starter Anil Gupte
  • Start date Start date
A

Anil Gupte

In one VB.Net 2003 solution, I have three projects (one in the installer
project and not relevant here). However, the other two are the ones where I
want to share some commone fucntions. One is a Windows Forms based app and
the other is a Windows Service. Is this possible?

TIA,
 
Anil Gupte said:
In one VB.Net 2003 solution, I have three projects (one in the installer
project and not relevant here). However, the other two are the ones where
I want to share some commone fucntions. One is a Windows Forms based app
and the other is a Windows Service. Is this possible?

You put the functions in a public class like this.

Public Class Test

Public Shared Function test(ByVal msg As String) As String

Return msg

End Function

End Class

Then you can do something like this with a Messagebox as an example.

Messagebox(Test.test("Help"))

You can put the Test class in your projects.

It's just an example.
 
Anil,

As long as you build them as Class Librarys you can do everything with the
public methods and properties in the resulting DLL's.

(You have to set a reference to that).

Cor
 
Personaly i would avoid shared methods , i believe it is bether coding
practice to construct an object and dispose of it when done with it
nowadays i implement the idisposable pattern in all of my custom classes and
use them with the using statement to make sure i am not wasting anny
resources

but as i said this is a personal opinion
 
Personaly i would avoid shared methods , i believe it is bether coding
practice to construct an object and dispose of it when done with it
nowadays i implement the idisposable pattern in all of my custom classes and
use them with the using statement to make sure i am not wasting anny
resources

but as i said this is a personal opinion

Why do you implement the disposable pattern on all custom classes?
That seems a little overkill - since it won't really buy you anything
unless your are making use of unmanaged resources.
 
since it won't really buy you anything
unless your are making use of unmanaged resources.

Well it actually does give me something , variabels used inside a using
stament are out of scope as you leave the using statement
for grouping purposes this makes the code in my opinion a lot bether
readable .
also
i use a lot of data intensive resources , so with the using stament i can
write a class level table adapter use this in all my methods an get rid of
it through the idisposable pattern .

it also doesn`t hurt to implement idisposable , it just gives you some extra
coding options wich i like verry much


Michel



"Tom Shelton" <[email protected]> schreef in bericht
Personaly i would avoid shared methods , i believe it is bether coding
practice to construct an object and dispose of it when done with it
nowadays i implement the idisposable pattern in all of my custom classes
and
use them with the using statement to make sure i am not wasting anny
resources

but as i said this is a personal opinion

Why do you implement the disposable pattern on all custom classes?
That seems a little overkill - since it won't really buy you anything
unless your are making use of unmanaged resources.
 
Are you sure - I am talking abuot sharing the same class and/or functions
between two separate executables?

Anyway, I will try it and let you know.
 
So, I have to create a separate project to build a dll containing the shared
functions? Is there any example code out there on how to do this? Or even
on building a dll - preferably exposing more than one function?

Thanx,
 
Anil Gupte said:
So, I have to create a separate project to build a dll containing the
shared functions? Is there any example code out there on how to do this?
Or even on building a dll - preferably exposing more than one function?

You make a Class Library project, the class is public, the functions in the
class are public, you compile the Class Library project to make the DLL,
that you set reference to the DLL in your project wanting to use the Dll,
and you insatiate the class object just like any other object to use its
methods.

<http://www.google.com/search?hl=en&q=creating+a+Class+Library+project+VB.net&btnG=Google+Search>

You can also include the project in a Solution a .sln with other projects
and set Project Reference to the project so that you can debug functions
being used by the project using the Class Library.
 
Anil Gupte said:
Are you sure - I am talking abuot sharing the same class and/or functions
between two separate executables?

Anyway, I will try it and let you know.

You really were not giving any particulars, but you should remember it, the
Shared keyword, look it up.
 
Back
Top