Shared module ?

Moorzee

Well-known member
Joined
May 31, 2006
Messages
92
Location
England
Programming Experience
3-5
Shared module in VB6...What now?

In vb.net what should I use instead? Should I be creating a class called something like clsGeneralFunctions and referencing this from future apps or what?

AAArrrrrggggggghhhhhhhh. Head is hurting with vb.net :(
 
In vb.net every thing you place into a module is shared, therefore you do not need an instance of the class to use the functions/subs declared within. So a shared module in vb is a module in vb.net. Infact a module in vb.net is just another type of class. At compile in will be wrapped in class/end class statements and executed like any other. If you've got things like general function/utility functions then i would place them in a module.
 
I've stopped using modules in VB 2005. Not that there's anything wrong with them but I now use the ApplicationEvents.vb file. This file exists specifically for you to handle application events, like Startup and UnhandledException, but you can put other members in there as well. If you were to declar a function named SomeFunction in the ApplicationEvents.vb file it will then be available throughout your project as My.Application.SomeFunction. That seems appropriate to me. The only reason I would use a module instead as if I had a lot of members that I felt needed categorisation in more than one module. Frankly though, if that's the case then you probably haven't designed your app properly in the first place.
 
jmcilhinney said:
This file exists specifically for you to handle application events, like Startup and UnhandledException, but you can put other members in there as well. If you were to declar a function named SomeFunction in the ApplicationEvents.vb file it will then be available throughout your project as My.Application.SomeFunction.

What about if in the future I have multiple apps for my organisation though(not in the same proj/solution)? I then need to copy and paste from the ApplicationEvents file to each corresponding file?
 
If you want to use the same functions in multiple projects then I'd be making them Shared methods of a class and declaring that class in a library, i.e. DLL. I would only use a module within a project.
 
Back
Top