# How to use Modules

- How to use Modules
  - The Program
  - The Code:
    - Fmain.class
    - Mjo.module
  - The Source
  In a Module you can place methods (subs or functions), which are accessible for all other methods in the project.
  It is easy to use because you do not have to instantiate an object, as with a class, before you can access its methods.
  BUT ... There are no modules in the system of object oriented programming.
  (And you can't make Gambas libraries out of modules either. But they sure are handy for migrating existing VB code over to Gambas. - RobKudla 7 July 2003)
  I recommend not using modules.
  Better to write a class with the right mix of public and private members! It may seem to be a bit more work, but this way your style of programming may be much clearer.

  ## The Program

  ## The Code:

  ### Fmain.class

      STATIC PUBLIC SUB Main()
        hForm AS Fmain
        hForm = NEW Fmain
        hForm.show
      END

      PUBLIC SUB Button1_Click()
        Label1.Text = Mjo.sayHello(TextBox1.Text)
      END

  ### Mjo.module

      PUBLIC FUNCTION sayHello(name AS String) AS String
        RETURN "Hello " & name
      END

  ## The Source

  Download