Today I used paging when doing a project with ASP. It took me a long time to calculate the total number of pages. When setting the number of records displayed on each page to be different, the calculation of the total number of pages was always wrong. So I checked other people's algorithms online and now Use it to share relevant code
The following are three methods I found on the Internet for calculating the total number of pages during ASP paging. This method only calculates the total number of pages during paging, not the entire paging code:
Method one
The code is as follows:
'HTMer_RecordCount is the total number of pages to be calculated
' HTMer_RecordCount is the number of record sets
' HTMer_PageSize is the number of records per page
If HTMer_RecordCount Mod HTMer_PageSize=0 Then
HTMer_PageCount=Int(HTMer_RecordCount/HTMer_PageSize)
Else
HTMer_PageCount=Int(HTMer_RecordCount/HTMer_PageSize)+1
End If
Method two
The code is as follows:
'HTMer_RecordCount is the total number of pages to be calculated
' HTMer_RecordCount is the number of record sets
' HTMer_PageSize is the number of records per page
HTMer_PageCount=Int(HTMer_RecordCount/HTMer_PageSize*-1)*-1
Method three
The code is as follows:
'HTMer_RecordCount is the total number of pages to be calculated
' HTMer_RecordCount is the number of record sets
' HTMer_PageSize is the number of records per page
HTMer_PageCount=Abs(Int(-(HTMer_RecordCount/HTMer_PageSize)))
Method four
The code is as follows:
'HTMer_RecordCount is the total number of pages to be calculated
' HTMer_RecordCount is the number of record sets
' HTMer_PageSize is the number of records per page
HTMer_PageCount=Fix(HTMer_RecordCount/HTMer_PageSize)-CInt(CBool(HTMer_RecordCount Mod HTMer_PageSize))