When writing a paging class, I encountered a very clever problem of class object reference passing. If I explain what is going on here, it may be difficult for everyone to understand clearly. It is better to look at the code, which uses a paging class CPaging.
Copy the code code as follows:
Class CPaging
Public RS ' RecordSet object
Public Mark ' pointer label
Private sSize ' Number of displays per page
Private sTotal 'Total number of records
Private sPage 'Current page number
Private sCount 'Total page number
Private Sub Class_Initialize
sSize = 20
sPage = 1
sCount = 1
End Sub
Private Sub Class_Terminate
Closeobj RS
End Sub
'Display number per page
Property Let Size(Value)
sSize = Value
End Property
Property Get Size
Size=sSize
End Property
'Current page number
Property Let Page(Value)
If Not IsNumeric(Value) Then
sPage = 1
Else
sPage = Value
End If
End Property
Property Get Page
If (sPage - 1) * sSize > sTotal Then
If sTotal Mod sSize = 0 Then
Page=Total/sSize
Else
Page = Total / sSize +1
End If
ElseIf sPage < 1 Then
Page=1
Else
Page=sPage
End If
End Property
'Total page number
Property Get Count
If sTotal Mod sSize = 0 Then
Count = sTotal / sSize
Else
Count = sTotal / sSize + 1
End If
End Property
'Total number of records
PropertyGetTotal()
Total = sTotal
End Property
Public Function Open(Byval SQLString)
Try DB.Openquery(RS,SQLString)
sTotal = RS.RecordCount
End Function
End Class
The following is the calling page
Copy the code code as follows:
Dim Products
Set Products = New CPaging
With Products
.Size = 15 'Number of displays per page
.Page = PageNum 'Current page
End With
Try Products.Open(ListSQL)
If Products.RS.Bof and Products.RS.Eof then
Response.Write(<TR><TD colspan=8>Find no records</TD></TR>)
Else
Dim i
i = 0
Products.RS.Move (Products.Page - 1) * Products.Size
Do While Not Products.RS.Eof
Response.Write(<TR onmouseup=MouseUp(this); onmousedown=MouseDown(this); onmouseover=MouseOver(this); onclick=Click(this); onmouseout=MouseOut(this);>&vbCrLf)
Response.Write(<TD align=middle nowrap> & Products.RS(ProductsClassName) & </TD>&vbCrLf)
Response.Write(<TD align=left nowrap> & Products.RS(ProductsName) & </TD>&vbCrLf)
Response.Write(</TR>&vbCrLf)
i=i+1
If i >= Products.Size Then Exit Do
Products.RS.MoveNext
Loop
End If
When I saw line 8, I seemed to catch a glimpse of the shadow of .net - namespace?