Solved

Bas and Cls oo technique

Posted on 2004-09-23
16
343 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
[X]
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
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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 86

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

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

729 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