Solved

Bas and Cls oo technique

Posted on 2004-09-23
16
341 Views
Last Modified: 2010-05-02
Strange question.
Have seen some com component code where each the .cls methonds and basically just wrappers and call procedures in .bas modules. Apparantly this is supposed to help reusability? Has anyone come accross this before? Know why you would do it?
0
Comment
Question by:visual_b
  • 3
  • 3
  • 2
  • +3
16 Comments
 
LVL 11

Accepted Solution

by:
coopzz earned 32 total points
ID: 12132240
bascally it's to get an object orientated approach to something that isn't like the win32 api's.  and yer you'll see it all the time.

so what this helps with is creating a collection of related things that help do simular things, the Scripting.File System Object is a classic example. it's much easier to remember the object than it is all the procedure names.
0
 
LVL 18

Assisted Solution

by:JR2003
JR2003 earned 31 total points
ID: 12132261
It prevents all the source code being in the cls module and so helps with maintainability. The only access the external user of the com component is through the class module.
0
 
LVL 2

Assisted Solution

by:x_terminat_or_3
x_terminat_or_3 earned 31 total points
ID: 12132276
You can use classes to create new objects or to add functionality to existing objects.

The code required for the functionality of the class can be partly stored in a .bas file, specifically if the class module uses Api calls, the declares for them are usualy held in a normal module (.bas)


With kind regards



Ramses (x_terminat_or_3)
0
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
LVL 1

Author Comment

by:visual_b
ID: 12132309
COOPZ: But why not have the procedures in the .cls module?
JR: How does having the code in a bas module aid maintainability?
0
 
LVL 1

Author Comment

by:visual_b
ID: 12132328
x: But these modules don't contain any api calls? No reason that the code can't all be done in the .cls module. It seems to be a "style" thats being used...
0
 
LVL 11

Expert Comment

by:coopzz
ID: 12132338
sometimes you can't use the cls for doing certain things..

eg. if you building a dll project and you have more that one cls interface you may need to share a global varibles which you store in the bas files... and for the reuseability you can have some code that you use in different cls but dont' need to add it to all the cls

theres also that if your doing win32 call backs you can't use cls
0
 
LVL 10

Assisted Solution

by:fds_fatboy
fds_fatboy earned 31 total points
ID: 12132342
This technique is used a lot if two or more classes both need to implement the same Method. You put the method functionality in a routine in a mod and the interface/wrapper in the class. Therefore only one set of code to maintain.

It must be remembered that VB versions 1 to 6 are not oo languages. In true oo you would be more likely to place the method in an ancestor class and inherit your other classes from it.
0
 
LVL 18

Expert Comment

by:JR2003
ID: 12132624
visual_b
<<"How does having the code in a bas module aid maintainability? "
If you have many thousands of lines of code it will be more maintainable if you have them in more than one module.
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 12132953
Sometimes there is an API call in the class that requires a callback method.  To use a callback method, you must supply the address of a function in your project but you can only do this with a sub in a module.

Regards,

Idle_Mind
0
 
LVL 1

Author Comment

by:visual_b
ID: 12133313
fatboy: If two or more classes use the same method, why not just make it a public method of a class, that can also be called from anywhere.
JR: Not sure I agree with you. Think all code relating to a particular entity should be stored in the same module, in an oo style.
0
 
LVL 10

Expert Comment

by:fds_fatboy
ID: 12135486
visual_b
>>If two or more classes use the same method, why not just make it a public method of a class, that can also be called from anywhere.
You could  - I usually would. I was just explaining reasons not necessarily advocating them.There are advantages and disadvantages to usoing classes for everything. Thea main advantage is keeping your code where it is used is and highly maintainable, memory is not shared between instances of objects making it easy to know that your mod level variables are safe. Advantages of mods are classes are much slower to run code from than mods, memory is shared in mods making it possible to use AddressOf callbacks. You can't have a sub Main in a class.


>>Think all code relating to a particular entity should be stored in the same module, in an oo style.

Yes to a point - In VB6 is not oo. I have in the past used oo languages, and now again am again with dotnet.
With VB6, I personally take a pragmatic approach I do tend to put most of my functionality in classes and ultimately in DLLs - usually COM+, but some things I have live in mods - especially when subclassing controls.  
0
 
LVL 10

Expert Comment

by:fds_fatboy
ID: 12582431
Split points to all participants??
0
 
LVL 2

Expert Comment

by:x_terminat_or_3
ID: 12582456
concur
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

856 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