What is the difference between module and form in vb

Hi everyone, I need a bit of clarity when it comes to the difference between module and forms in vb
Joel SiiiAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Pawan KumarDatabase ExpertCommented:
Form - GUI ( graphical user interface ) It is something that the the user will have interaction with. It can and usually does contain code specific to the controls that exist on the form. These might be buttons, listboxes, etc.

A module in vb is used to encapsulate code. At its purest form a module would contain code used for specific tasks and a new module would be used for other specific tasks.

In the past, I have created modules that contain utility routines that I find I use frequently. I can then include the module of my utility routines into any new project I have and reuse that code.

Code or functions/subs in a VB form can be addressed using the Me prefix. A module does not exist within a form, so that context is not available.

A module would be a part of the application.

From old EE database.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Martin LissOlder than dirtCommented:
A module does not exist within a form, so that context is not available.
That's not true. The code behind forms/userforms is referred to as the "form module".
0
JohnCommented:
Forms are modules, but they are also a class.  Apart from the obvious (A form has a UI), this is the main difference.  

A module is not a class.  

With a class you can create an instance, which you can't do with a module.  You can also called static methods which is like calling a sub or function from a module.
0
Máté FarkasDatabase Developer and AdministratorCommented:
Form: this is an object which copies a build in class UserForm in VB. Your Form object has some initial capabilities:
      - has a window with common window controls (close, minimize, maximize, resize with mouse)
      - can draw itself on the screen (with Show method) or hide (with Hide method)
      - can contain other control like buttons (CommandButton), text fields (TextBox)
      - can manage keyboard and mouse events
      - etc. you can extend the capabilities with your methods and controls
Form is similar to Class.

Module: this is only a code file which contains some functions, procedures, variables which are independent for any other Forms or Classes. You can call your functions from your module in any part of your program.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VB Script

From novice to tech pro — start learning today.