Click here to Skip to main content
15,891,864 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have been told to keep common subs and functions inside a module and call them from there, is this right?

What I have tried:

I have tried a module and it works fine but wondered if it was the right way.
Posted
Updated 20-Jun-17 19:04pm
Comments
PIEBALDconsult 20-Jun-17 23:28pm    
Yes.

1 solution

Yes, it's the right way: the alternative is to use a class full of Shared methods, and that gets messy, because a class should be designed for inheritance and instantiation - which isn't possible with a Shared method. Modules are the VB counterpart of C# static classes, and are the only way you can do some things, such as extension methods for example.
Using a module lets you declare methods that are available anywhere the module is without needing to preface the method name with the class.
 
Share this answer
 
Comments
BeginnerCoderPete 21-Jun-17 8:06am    
Excellent, Thank you!
OriginalGriff 21-Jun-17 8:16am    
You're welcome!
BeginnerCoderPete 21-Jun-17 16:49pm    
Is it possible to pass a TableAdaptor from my Form to the Module?
OriginalGriff 22-Jun-17 0:24am    
Yes. You can pass anything to anywhere by passing it as a parameter.
BeginnerCoderPete 22-Jun-17 4:11am    
The problem is though that Table Adaptors don't have a base class so I can't do what I'd normally do and say (ta as TableAdaptor) so I was trying to find another way. I thought maybe pass the name through as a string then somehow find the table adaptor with an name that matches. I ran into difficulties there too.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900