Solved

Newbie Question - No Code Required

Posted on 2000-04-27
14
211 Views
Last Modified: 2010-05-02
Hi,
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.

diek
0
Comment
Question by:diek_nf
  • 4
  • 2
  • 2
  • +6
14 Comments
 
LVL 2

Expert Comment

by:Sage020999
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.
0
 

Expert Comment

by:IsaacRU
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.
0
 

Author Comment

by:diek_nf
ID: 2756143
IsaacRU,
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.

diek
0
 

Author Comment

by:diek_nf
ID: 2756193
Hi,
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.

diek
0
 

Expert Comment

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

Expert Comment

by:bhess1
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?
0
 
LVL 1

Expert Comment

by:4P
ID: 2756371
Hello,

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.
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Expert Comment

by:GreatMikey
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
0
 

Expert Comment

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

Author Comment

by:diek_nf
ID: 2756470
Mikey,
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.



diek
0
 

Expert Comment

by:LeXien
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.
0
 
LVL 6

Expert Comment

by:Marine
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. :)
0
 

Accepted Solution

by:
shideyi earned 20 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.
0
 

Author Comment

by:diek_nf
ID: 2758862
Everyone,
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.

diek
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

758 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now