intOldPageLength = GetPageLengthValue() ' if there is a new page length value If intOldPageLength <> m_intPageLength Then ' adjust the page number to compensate intItemCount = ((m_intPage - 1) * intOldPageLength) + 1 m_intPage = intItemCount \ m_intPageLength If intItemCount - (m_intPage * m_intPageLength) > 0 Then m_intPage = m_intPage + 1 End If End If
The index of the first item on the current page happens to be a count of the items up to that point. So assume we are paging that amount and use the last page as our new current page. We apply standard paging logic of items integer divided by page length to determine the number of pages and add one if there is a remainder.
There are a couple formulas at work here worth noting.
Index of Last Item on page:
page number * page length
Index of First Item on page:
(index of last item of previous page) + 1
((page number - 1) * page length) + 1
Page Count based on page length:
number of items [integer divide] page length
if there is a remainder to the above then add 1