|
-
Jun 7th, 2008, 02:01 AM
#1
Thread Starter
Fanatic Member
Module in VB.NET
Hello,
I m new to VB.NET, i have worked in VB.
My question is that we make MODULES in vb 6 for those functions which are normally use in our porject, like Center Form, Highlight Text etc..
Can we make these kind of modules in VB.NET ???
Thanks in advance
-
Jun 7th, 2008, 02:17 AM
#2
Re: Module in VB.NET
You certainly can create a module in VB.NET. You just right-click the project and select Add Module. That said, you should use modules very, VERY sparingly. Most projects have no need for modules. Use them only for utility members that don't logically belong to any specific class.
-
Jun 7th, 2008, 02:27 AM
#3
Re: Module in VB.NET
What did you have in mind to place in a module?
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jun 7th, 2008, 02:37 AM
#4
Thread Starter
Fanatic Member
Re: Module in VB.NET
Different procedures and functions.
-
Jun 7th, 2008, 02:41 AM
#5
Re: Module in VB.NET
Probably should be in a class as its more OOP but almost everything should be in a class anyways.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jun 7th, 2008, 03:18 AM
#6
Re: Module in VB.NET
Like I said, only members that don't logically belong to any specific class should be placed in a module and no project should have many of those. For instance, if you want a method to centre a form on-screen then you could inherit the Form class and add a method for the form to centre itself. Any of your forms that then need that functionality can inherit that class instead of the Form class.
Remember that in VB 2008 you can also create extension methods, IF you're targeting .NET 3.5. These MUST be declared in a module but then are called as though they are members of an object. Here's an extension method that will centre a form on screen:
vb.net Code:
Imports System.Runtime.CompilerServices Friend Module FormExtensions <Extension()> _ Public Sub CenterOnScreen(ByVal extendee As Form) Dim screenArea As Rectangle = Screen.PrimaryScreen.WorkingArea extendee.Location = New Point((screenArea.Width - extendee.Width) \ 2, _ (screenArea.Height - extendee.Height) \ 2) End Sub End Module
You might call that method in a form like this:
vb.net Code:
Private Sub Button1_Click(ByVal sender As Object, _ ByVal e As EventArgs) Handles Button1.Click Me.CenterOnScreen() End Sub
Notice that it's called as though it's a member of the current form, even though it's not. Intellisense uses a different icon to identify extension methods so you can tell them from actual members.
Notice, also, that it's called without arguments even though it is declared with a parameter. That's because the first object the method is called on is always passed to the first parameter.
Last edited by jmcilhinney; Jun 7th, 2008 at 03:24 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|