Page Indicator - a puzzle

I am trying to create a custom control similar to what you see on some webpages, but this is for a desktop app.

Given

  • currentPage - an integer value indicating the page number of the current page
  • maximumPage - an integer value indicating the highest page number allowed

Controls

  • prevPage
  • nextPage
  • gotoPage()
    these are all bevel buttons… there will be no more than ten(10) gotoPage buttons

The need is to display a horizontal control starting with [prevPage], followed by 1 to n [gotoPage], ending with [nextPage]
the gotoPage buttons will have a numeric caption indicating the “page” to goto :slight_smile:

The number of gotoPage buttons will be determined by “maximumPage”… (ie. min(10,maximumpage) )

the problem is determining what starting caption when refreshing the control…
I don’t want the values in gotoPage to jump around …

my original idea was something like

Dim i As Integer
Dim btn1 As Integer
Dim btn2 As Integer
Dim clr As Color
//
For i=0 To 9
	bbGOTO(i).Visible=False
Next

If CurrentPage>=1 Then 
	btn1=Max(1,CurrentPage-4)
	btn2=Min(maximumPAGE,btn1+9)
End If
//
For i=0 To 9
	If btn1>btn2 Or btn1=0 Then Exit For
	clr=&c000000
	If btn1=CurrentPage Then clr=&C007700
	bbGOTO(i).Caption=Str(btn1)
	bbGOTO(i).TextColor=clr
	bbGOTO(i).Visible=True
	btn1=btn1+1
Next

That looks reasonable. What problem(s) does it raise?

if the buttons are showing [5][6][7][8][9][10]
and you click on [7] want the [7] to change color obviously
but I DONT want the order to change to [4][5][6][7][8][9]

But isn’t that the expected behavior? (Of course, you would normally have an odd number of pages showing, so there would be the same number of options on either side of [7], unless it were near the end of the list, which it obviously isn’t in your example.)

Perhaps what you’re really looking for is

if CurrentPage< 5 then
   btn1 = 1
else if CurrentPage> maximumPage-5 then
   btn1 = maximumPage - 9
else
   btn1 = CurrentPage - 4
end
btn2 = min(maximumPage, btn1+ 9)

Hi Dave.

A variation of this might work…

  1. Show links for an odd number of pages.
  2. If a link is clicked (page link or prev / next) update the range displayed if the new value is 1 from either end.

Example:
Current range displayed:
[prev] [5] [6] [7] [8] [9] [10] [11] [next]

so…
Clicking 7, 8, 9 (or using prev / next to hit those pages) would not change the range.
Clicking 5 , 6, 10, 11 (or using prev / next to hit those pages) would update the range.