I used VB a long time..

i never manipulate a Class..

I just want to know what is the concept in using a class..

because i already graduated in an IT course, and then im eventually working with VB
with a back-end SQL Server 2000.

when i look at their projects.. i saw Classes, much more than Modules.

can someone explain me the concept of Class? can you give examples?

Dani AI

Generated

A class is a blueprint for an object: it groups related data (fields) and behavior (methods) so you can create one or many independent instances. Compared with a Module (which holds globals and shared procedures), a Class gives each object its own state, makes code easier to reason about, and helps separate UI, business logic, and database access — useful when your back end is SQL Server.

As suggested, tutorials are a good start. As noted, you can declare variables at class level — that is fine for simple storage, but prefer encapsulation via properties so you can validate or control access later.

Example (VB6-style class module pattern):

' Class module: clsCustomer
Private mID As Long
Private mName As String

Public Property Get ID() As Long
    ID = mID
End Property

Public Property Let ID(ByVal v As Long)
    mID = v
End Property

Public Property Get Name() As String
    Name = mName
End Property

Public Property Let Name(ByVal v As String)
    mName = v
End Property

Public Sub LoadFromDB(ByVal conn As ADODB.Connection, ByVal id As Long)
    ' execute parameterized query, populate mID/mName from recordset
End Sub

Practical workflow: identify real entities (Customer, Order, Product), create small classes that hold state and basic operations, put all SQL calls in a dedicated Data Access class (parameterized queries only), and keep forms thin (presentation only). Troubleshooting notes: in VB6 clear object references (Set x = Nothing), close recordsets and connections promptly, and avoid long-lived global connection objects. Also watch for circular references (they cause leaks in VB6). Using classes makes code easier to test and maintain as your project grows.

Recommended Answers

All 3 Replies

There is numerous tutorials when you use Google search. Try the search criteria "Class objects in VB6". Have a look at the following link, choose the one you need and happy learning.

http://www.google.com/search?q=w&rls=com.microsoft:en-US:{referrer:source?}&ie=UTF-8&oe=UTF-8&sourceid=ie7&rlz=1I7WZPA_en

Or have a look at the following - "class in vb6 tutorial"

http://www.google.com/search?q=w&rls=com.microsoft:en-US:{referrer:source?}&ie=UTF-8&oe=UTF-8&sourceid=ie7&rlz=1I7WZPA_en#sclient=psy&hl=en&rls=com.microsoft:en-US%3A%7Breferrer%3Asource%3F%7D&rlz=1I7WZPA_en&source=hp&q=class+in+vb6+tutorial&aq=1&aqi=g2g-m8&aql=&oq=class+in+vb6&gs_rfai=&fp=499faa430ac3503f

Puiblic strA As String
Puiblic intA As Integer
Puiblic strB As String
CAN BE DECLARED AT cLASSmODULE LEVEL.

It can even be declared at the GeneralDeclaration section of the Private Modules.
SAJAN666
PIN695311
KERALA
INDIA

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.