O.k. first of you declare the class, private variables and code for when the
class is first instantiated. As I said you must understand what is involved in
making a class or you might be a bit confused:-
Class caDataGrid
'private variables
private pAutoColumns, pConnStr, pSqlStr, intColCnt
Private pOutPut, pConn, pRec, x, y, pArray
'this runs when you create a reference to the caDataGrid class
Private Sub Class_Initialize()
Set pConn = server.createobject("adodb.connection")
Set pRec = server.createobject("adodb.recordset")
intColCnt = 0
pAutoColumns = True
End Sub
When the Class initializes we set our connection object and recordset object
as adodb objects. We also set the Column Count variable to 0 for use when we
want to define our own columns and finally we default to AutoColumns=true. It's
in this procedure you would put any defaults you want for your class.
Next we create the procedures that allow us to set the various proerties:-
'Properties - all writable
Public Property Let ConnectionString(strConn)
pConnStr = strConn
End Property
Public Property Let AutoColumns(bAutoCols)
If bAutoCols = True or bAutoCols = False then
pAutoColumns = bAutoCols
End IF
End Property
Public Property Let SqlString(strSql)
pSqlStr = strSql
End Property
I haven't included code for reading these values, 'Public Property Get', as we
don't really need to do this. I'm skimping a bit on error checking but the procedure
to set the AutoColumns boolean checks to make sure only true or false is passed
to it, for example. Otherwise in this case it remains true from the initializing
code. It's a good idea to include more complete error code for these procedures
to ensure proper values are set and especially if you wanted to make your class
widely available.
Comments