I'll do both. Without going into crazy whacky details, a class is basically the base for creating your own objects. In order to do this, you add a "Class Module" to Your VB6 project, and you can build your own object. This object can be anything and do anything... it can have it's own properties, it's own methods, a constructor, and a destructor. In VB you can then instantiate an instance of this class as an object, and use it just like any other object.
What is a class?
A class can be defined a structure that is composed of two things:
- Data Members.
A class is designed to be reused, when using a class we dont have to know, how it is designed, we just need to know the interface and methods signatures.
Why using a class in vb?
We use class to create composant that can be reused in other application.
Such example, creating a class that do the following:
- Create an ODBC connection to a Database,
- Create an OLEDB connection,
- Get a recordset from the DB,
- Execute Function (Insert, Update, ...statements)
- Check if a connection status to a DB,...
As you can se this functions are already used to deal with a DB.
How to use a class?
You have to create an instance of that class (called object)
We have a compoent called dataLayer in which there is a class called clsDataLayer, some of it's methods are ODBCConnect,GetDisRecordsetPage...
Dim oData as new datalayer.clsdtalayer
Dim MyCnn as new adodb.Connection
hi comatose sorry its only now i checked my port here...anyway, i would love you'll give me a simple example together with an explanations. because i just find it hard to build my own class, i have difficulty in understanding the procedure of making it.
When we want to reuse a functionality, Classes can be used. A module for instance, could be used for a particular form only.
In an accounting application a Class can be used in the following instances:
a.When we want to access data from a database
b.Log in feature in the application
In the title "Develop an Accounting Package using VB", i have dealt with this topic in detail....A class has been developed and when we save data into the database, retreive, edit, adding and displaying data. All the financial transactions use the Class - Tran Class.
If you notice, suppose we have a Cash Payment transaction, this transction uses the same class as the Cash Voucher transaction uses. I have dealt with how to design single form, and use the same form for different transactions like CV, CP etc, which is OOPs.
If we use a module, we will need to create separate modules .....
Each entity also can be created as a class.
Class based design forces us to think ahead in terms system design and implenting the requirements in a project and thus save on all resources like time, money etc.