CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: Modules

  1. #1
    Join Date
    Jan 2000
    Posts
    45

    Modules

    i dont really fully understand what a module is for. can you please help me understand¿


  2. #2
    Guest

    Re: Modules

    Basically Modules are for holding public subroutines/variables and constants in your project.
    Anything that you declare as public in a module can be accessed by all forms in your project.
    The same is true if you declare something as public at the form level but if you reference a public routine in a form then that form will get loaded into memory so putting them in modules is the best answer



  3. #3
    Join Date
    May 1999
    Location
    Oxford UK
    Posts
    1,459

    Re: Modules

    Take a look at :

    http://codeguru.developer.com/bbs/wt...age=&view=&sb=


    Chris Eastwood

    CodeGuru - the website for developers
    http://codeguru.developer.com/vb

  4. #4
    Join Date
    Aug 1999
    Location
    US, Florida
    Posts
    817

    Re: Modules

    I'll try to explain really simple.....module is just basically a lot of code putted into one call
    for example you have 20 command buttons and each does the same thing, for example when pressing each command button this code is executed:

    Form1.Text8.Text = GetFromIni("1", "X", App.Path + "\Settings.ini")
    Form1.Text9.Text = GetFromIni("1", "Y", App.Path + "\Settings.ini")
    Form1.Text10.Text = GetFromIni("1", "MIN", App.Path + "\Settings.ini")
    Form1.Text11.Text = GetFromIni("1", "SEC", App.Path + "\Settings.ini")
    Form1.Text12.Text = GetFromIni("1", "#", App.Path + "\Settings.ini")
    '2======================
    Form1.Text13.Text = GetFromIni("2", "X", App.Path + "\Settings.ini")
    Form1.Text14.Text = GetFromIni("2", "Y", App.Path + "\Settings.ini")
    Form1.Text15.Text = GetFromIni("2", "MIN", App.Path + "\Settings.ini")
    Form1.Text16.Text = GetFromIni("2", "SEC", App.Path + "\Settings.ini")
    Form1.Text17.Text = GetFromIni("2", "#", App.Path + "\Settings.ini")
    '3======================
    Form1.Text18.Text = GetFromIni("3", "X", App.Path + "\Settings.ini")
    Form1.Text19.Text = GetFromIni("3", "Y", App.Path + "\Settings.ini")
    Form1.Text20.Text = GetFromIni("3", "MIN", App.Path + "\Settings.ini")
    Form1.Text21.Text = GetFromIni("3", "SEC", App.Path + "\Settings.ini")
    Form1.Text22.Text = GetFromIni("3", "#", App.Path + "\Settings.ini")



    (That was just an example from my program) so now when you press command3, or 4 or 5 you will have to type all those lines again, but if you use module, you could place all those lines into a module

    public Sub SaveData ()
    all those lines
    End Sub



    and from each command button call that public sub

    private Sub Command1_Click()
    Call SaveData
    End Sub
    private Sub Command2_Click()
    Call SaveData
    End Sub
    etc.



    now all you need is to place Call SaveData into command buttons instead of 15 or more lines of code that saves you a lot of coding time and it decreases size of the program


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

Featured