Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Buttons to activate Prev / Next page, logic improvements
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Autre
Versions des environnements
Visual FoxPro:
VFP 9 SP1
Divers
Thread ID:
01383298
Message ID:
01383422
Vues:
50
Hi Martina

>But your source code is complex...

Thanks for the efficient code and yes maybe that was why I was loosing out quick. I have put in more code at the bottom where the first control gets focus on the activated page. Also added a condition to check if the current page was subsequently made hidden (ie. Add New Record default minimum pages):
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
Regards
Bhavbhuti
___________________________________________
Softwares for Indian Businesses at:
http://venussoftop.tripod.com
___________________________________________
venussoftop@gmail.com
___________________________________________
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform