allida77
12-06-2003, 04:47 PM
I have run into a problem that has existed for while but it has just now come to my attention. I have a page that returns a large amount of rows that I recently converted from using ado paging to the getRows() method. Well it sped up the page two fold and I thought that it was perfect (which is why I now have a problem :D). I have now realized a problem when I am trying to get the total number of pages. I get the total number of pages by the number of rows the client wants to see per page divided by the recordcount. So :
1000 (total records) / 100 (records per page) = 10 total pages
The problem lies when the division returns a remainder:
1000 (total records) / 30 (records per page) = 33.3 pages
So the logic is anytime the number of pages has a decimal you should +1. Easy enough but I have not found a simple way in vbscript to do this. So this is what I have:
'This tells me if there will be a remainder
If (iRecordCount Mod iRows) > 0 Then
iPageCount = CInt(iRecordCount / iRows) + 1
End If
Notice I use CInt() for the number and add 1. I thought by using CInt() it would just drop its decimal value. Well it does that and it also will round up. So if I have 33.7 doing a CInt(33.7) gives me 34 then I would add 1 creating to many pages. Is there a way to just drop the decimals on a number without rounding?
Currently my solution will be to check to see if the MOD is > .5. If so then I do not add one, if it is less then I add one. I am not sure why CInt() rounds in vbscript.
1000 (total records) / 100 (records per page) = 10 total pages
The problem lies when the division returns a remainder:
1000 (total records) / 30 (records per page) = 33.3 pages
So the logic is anytime the number of pages has a decimal you should +1. Easy enough but I have not found a simple way in vbscript to do this. So this is what I have:
'This tells me if there will be a remainder
If (iRecordCount Mod iRows) > 0 Then
iPageCount = CInt(iRecordCount / iRows) + 1
End If
Notice I use CInt() for the number and add 1. I thought by using CInt() it would just drop its decimal value. Well it does that and it also will round up. So if I have 33.7 doing a CInt(33.7) gives me 34 then I would add 1 creating to many pages. Is there a way to just drop the decimals on a number without rounding?
Currently my solution will be to check to see if the MOD is > .5. If so then I do not add one, if it is less then I add one. I am not sure why CInt() rounds in vbscript.