Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


Newbie Question - No Code Required

Posted on 2000-04-27
Medium Priority
Last Modified: 2010-05-02
I am looking over the code that accompanies "Read-Before-Write Prevents User Conflicts" by Basil McDonnell from Getting Started with Visual Basic, Spring 2000.

Mr. McDonnell uses 4 class files, AuthorsLiteTest group, a bas file.

I have gone through the code and I cannot:

1. Determine when a bas module or a class module should be used; and

2. Figure out what is the difference between a group and a project.

Any help would be appreciated. Thank you.

Question by:diek_nf
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
  • 2
  • +6

Expert Comment

ID: 2756108
A .bas module should contain any code that may be called from multiple forms.

A class module should group together any code that you wish to perform a certain function.

Some people work on multiple projects at a time.  You can load and save these in a group.  You will see this if you add more than one project to your VB workspace.

I hope this helps.

Expert Comment

ID: 2756122
The Comment for Sage was great i just have some things to add

You can also use .bas moddules in multiple projects to cut down on programming time.

Class Modules are extremely useful for creating objects, and simplified routines.

Author Comment

ID: 2756143
Thank you. If you thought Sage's was great why did you submit your's as a proposed answer. I hope that didn't sound rude.

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.


Author Comment

ID: 2756193
I just want to give this question a little more time, before I close it. IsaacRU and Sage,both you made this alot clearer. Thank you.


Expert Comment

ID: 2756268
Sorry what I meant was to post it a comment.
LVL 32

Expert Comment

by:Brendt Hess
ID: 2756370
Generally, I would use a Class where I would use an Object in Object Oriented (OO) coding, and a .BAS module where I am using code that is either (a) specific to a single program, or (b) usable in multiple places.

An object, as used in OO coding, can be pictured as a group of data (like a user defined data type), and the associated code (methods) for manipulating the data.  That is, if you had a Customer User Defined data type, you could build a Customer class with that data structure that included all of the data validation routines, load/save code, etc. for your Customer.  Any program that needed to reference the Customer could just use the Customer class module.

In the .BAS module(s), you might have:
  Generic validation routines.
  Generic printing routines.
  Generic DB opening routines.
  Generic login/security routines
  Program Specific validation routines.
  Program Specific printing routines.
  Other program specific code.
    NOTE:  All program specific code associated with a form should be in the .FRM, if possible.

Does this help any?

Expert Comment

ID: 2756371

a bas module can contain procedures and functions. You would use a bas module to code elements that you want to use globally in THAT application. For example an output formatting function that you want to access from multiple forms.

Calss modules are more complicated, but basically with a class module you can create an object. You would use a class module to code elements that you want to access from MULTIPLE applications. In addition, objects can be structured real well with the properties / methods / events.

Of course you can add a bas module to multiple applications but you need to be carefule because that can lead to version conflicts.

A project consists of different files that will make up your application. This can include bas modules, class modules, forms, and so on.

A group is a group of projects. It is useful when you want to test a ActiveX component. You create a project for the Active component, and another one that is a "tester" aplpication, and then you can load both projects at the if you put them into a group.

Hope this is what you were looking for.

Expert Comment

ID: 2756382
i also had teh same confusions when i started!!!
the reason you create .bas mosules is so that you can use them n e ware in you project without goung form1.blar(1323)
 you can just have modmain.blar(1323)
makes no sence but it does tidy up the code it means its more understandable you can group functions that do extra math together into one module and group functions that do graohis together. best of all the .bas file can be reused in later projects so therefore saves you time at a leterdate without having to copy code from old projects.

a class module is used when you want to make an object (i.e. a module with variables and code that) this object can be recreated again and again in the same project i.e. what i do when i simulate particles is create a particle class module. then in teh main code i add
privete ObjectInMyForm(number of them) as New ClassModuleName
this basicaly meand i have thousands of particles each with its own data and own processing code so cleaning up my form code

sorry its so long to explain hope it helps

Expert Comment

ID: 2756388
sorry i was so long writing i didnt see the other post

Author Comment

ID: 2756470
Thank you for replying. Rejecting your answer is nothing personnel, I found out quickly when I first joined that people are not too keen on proposed answers when I did it myself.

 You have locked my question, until I rejected your answer. Please do not get annoyed as some people get when their answers are rejected.

I am currently sorting out someone's code, so I cannot go through all the replies yet. I am going to take a break in when and read all the answers. I will give the points to the answer I feel is best. I am going to give this question a little more time. Thank you again and maybe your's is the one.


Expert Comment

ID: 2756644
a group is when you have have two projects in the same project. mmm, that doesn't make much sense. But say you have a DLL or something, that you may need to quickly modify for use in your program. You can easily switch between them.

Expert Comment

ID: 2757838
Well someone also have to mention about memory wise. Modules are loaded into Memory right away classes aren't. Classes only get loaded into Memory when they initilized, just like forms. :)

Accepted Solution

shideyi earned 60 total points
ID: 2757867
1. Determine when a bas module or a class module should be used
When you want to define varialbes or procedures you use bas module (standard module), normally varialbes and procedures declared in bas module are public and accessible through the whole project. Procedures can be Sub routines or Functions, there are reusable being declared in this way, that means, they are declared once and can be used anywhere in the project.
Class module is specially for Object Oriented Programming (OOP), VB is a programming language based on Class, Forms are class, Buttons are class, when you declare a form, you are declaring an instance of the Form class, VB allow you to define your own class, but you have to put the declaration in class module.
2. Figure out what is the difference between a group and a project
Group is just a environment that show more than 1 prject. As in VB4, you can only create project but not group, this is inconvenient. In cases of testing and debugging UserControl, it's better for you to create a group containing the project and the UserControl.

Author Comment

ID: 2758862
I had a bit of a hard time picking the best one, but shideyi's was clearest. Essentially I learned alot from everyone's commets. Marine, that was an excellent point.


Featured Post

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

719 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question