Results 1 to 6 of 6

Thread: Module in VB.NET

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    May 2004
    Location
    Quetta-Pakistan
    Posts
    852

    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

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    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 PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI 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

  4. #4

    Thread Starter
    Fanatic Member
    Join Date
    May 2004
    Location
    Quetta-Pakistan
    Posts
    852

    Re: Module in VB.NET

    Different procedures and functions.

  5. #5
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    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 PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI 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

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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:
    1. Imports System.Runtime.CompilerServices
    2.  
    3. Friend Module FormExtensions
    4.  
    5.     <Extension()> _
    6.     Public Sub CenterOnScreen(ByVal extendee As Form)
    7.         Dim screenArea As Rectangle = Screen.PrimaryScreen.WorkingArea
    8.  
    9.         extendee.Location = New Point((screenArea.Width - extendee.Width) \ 2, _
    10.                                       (screenArea.Height - extendee.Height) \ 2)
    11.     End Sub
    12.  
    13. End Module
    You might call that method in a form like this:
    vb.net Code:
    1. Private Sub Button1_Click(ByVal sender As Object, _
    2.                           ByVal e As EventArgs) Handles Button1.Click
    3.     Me.CenterOnScreen()
    4. 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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width