LPARAMETERS tcAdvanceTo IF TYPE("THISFORM.cmdPrevious.CAPTION") # "C" RETURN ENDIF LOCAL liY, lnI, loPrevPage, loCurrPage, loNextPage, ; loControl, lnMinTabIndex, loMinTabControl LOCAL ARRAY laOrder[1] WITH THISFORM DIMENSION laOrder[.pgf.PageCount, 2] liY = 0 *** create Array ordered by Page Order FOR lnI = 1 TO .pgf.PAGECOUNT *** only consider active pages IF (PEMSTATUS(.pgf.PAGES(lnI), "lVisible", 5) AND .pgf.PAGES(lnI).lVisible) ; OR ((NOT PEMSTATUS(.pgf.PAGES(lnI), "lVisible", 5)) AND .pgf.PAGES(lnI).ENABLED) liY = liY + 1 DIMENSION laOrder[liY, 2] laOrder[liY, 1] = .pgf.PAGES(lnI).PAGEORDER laOrder[liY, 2] = .pgf.PAGES(lnI) ENDIF NEXT IF liY > 0 DIMENSION laOrder[liY, 2] ASORT(laOrder, 1, -1, 0, 0) ENDIF *** Current Page liY = ASCAN(laOrder, .pgf.ACTIVEPAGE, 1, -1, 1, 8) *** if active page no longer found (hidden / disabled) IF liY = 0 RETURN ENDIF *** new current page IF PCOUNT() > 0 IF UPPER(tcAdvanceTo) = "PREVIOUS" IF liY = 1 liY = ALEN(laOrder, 1) ELSE liY = liY - 1 ENDIF ELSE IF liY = ALEN(laOrder, 1) liY = 1 ELSE liY = liY + 1 ENDIF ENDIF ENDIF *** current page reference (original or new) loCurrPage = laOrder[liY, 2] *** Set previous page IF liY = 1 loPrevPage = laOrder[ALEN(laOrder, 1), 2] ELSE loPrevPage = laOrder[liY - 1, 2] ENDIF *** set next Page IF liY = ALEN(laOrder, 1) loNextPage = laOrder[1, 2] ELSE loNextPage = laOrder[liY + 1, 2] ENDIF *** change the buttons caption .cmdPrevious.CAPTION = "<< " + loPrevPage.CAPTION .cmdNext.CAPTION = loNextPage.CAPTION + " >>" *** hide buttons as required DO CASE CASE loCurrPage.CAPTION = loPrevPage.CAPTION *** current and the prev are same only one button .cmdPrevious.MakeVisible(.F.) .cmdNext.MakeVisible(.F.) CASE loPrevPage.CAPTION = loNextPage.CAPTION *** next and the prev are same no buttons .cmdPrevious.MakeVisible(.F.) .cmdNext.MakeVisible(.T.) OTHERWISE *** both buttons active .cmdPrevious.MakeVisible(.T.) .cmdNext.MakeVisible(.T.) ENDCASE *** change the active page if requested *** ie called from the click of the next and prev buttons DO CASE CASE PCOUNT() = 0 CASE UPPER(tcAdvanceTo) = "PREVIOUS" .pgf.ACTIVEPAGE = loCurrPage.PAGEORDER CASE UPPER(tcAdvanceTo) = "NEXT" .pgf.ACTIVEPAGE = loCurrPage.PAGEORDER ENDCASE *** if a page has changed set focus to the first user field IF PCOUNT() > 0 lnMinTabIndex = 999999 loMinTabControl = .NULL. FOR lnPagesControls = 1 TO loCurrPage.CONTROLCOUNT loControl = loCurrPage.CONTROLS[lnPagesControls] IF INLIST(UPPER(loControl.BASECLASS), FOCUSABLECLASSLIST_DEF) ; AND loControl.TABINDEX < lnMinTabIndex ; AND loControl.VISIBLE AND loControl.ENABLED lnMinTabIndex = loControl.TABINDEX loMinTabControl = loControl ENDIF ENDFOR loMinTabControl.SETFOCUS() ENDIF ENDWITH