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
Titre:
Buttons to activate Prev / Next page, logic improvements
Versions des environnements
Visual FoxPro:
VFP 9 SP1
Divers
Thread ID:
01383298
Message ID:
01383298
Vues:
113
Hi all

I have finally come to my wits end. I have a form with a page frame and pages on it. The pages do not have the same PageOrder as that of the creation, so for eg. the 3rd page might have a PageOrder of 5 or may be it has a PageOrder of 2. There are 2 buttons on the form which when clicked are supposed to activate either the previous or next page as per PageOrder, of course the captions are adapated as soon as they are clicked. Yes, there are pages that are disabled / hidden, they are to be skipped. To tackle this I have the following code but I still cannot get the captions and activation right. Can someone look at the code and optimize / debug the most obviously flaws I might have looked missed.

Thanks.
LPARAMETERS tcAdvanceTo


IF TYPE("THISFORM.cmdPrevious.CAPTION") # "C"
	RETURN
ENDIF


LOCAL lnCurrPO, lnCurrPage, lcCurrCaption, ;
	lnMinPO, lnMinPage, lcMinCaption, ;
	lnMaxPO, lnMaxPage, lcMaxCaption, ;
	lnPrevPO, lnPrevPage, lcPrevCaption, ;
	lnNextPO, lnNextPage, lcNextCaption, ;
	lnAvailPO, lnAvailPage, lcAvailCaption


WITH THISFORM
	lnCurrPO      = .pgf.PAGES(.pgf.ACTIVEPAGE).PAGEORDER
	lnCurrPage    = .pgf.ACTIVEPAGE
	lcCurrCaption = .pgf.PAGES(.pgf.ACTIVEPAGE).CAPTION

	lnMinPO      = lnCurrPO
	lnMinPage    = lnCurrPage
	lcMinCaption = lcCurrCaption

	lnMaxPO      = lnCurrPO
	lnMaxPage    = lnCurrPage
	lcMaxCaption = lcCurrCaption

	lnPrevPO      = -999999
	lnPrevPage    = -999999
	lcPrevCaption = "-999999"

	lnNextPO      = 999999
	lnNextPage    = 999999
	lcNextCaption = "999999"

	lnAvailPO      = lnCurrPO
	lnAvailPage    = lnCurrPage
	lcAvailCaption = lcCurrCaption


	*** loop each and every page
	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)

			*** track the available, first and last page order and no.
			lnAvailPO      = .pgf.PAGES(lnI).PAGEORDER
			lnAvailPage    = lnI
			lcAvailCaption = .pgf.PAGES(lnI).CAPTION


			lnMinPO = MIN(lnMinPO, lnAvailPO)
			
			IF lnMinPO = lnAvailPO
				lnMinPage    = lnAvailPage
				lcMinCaption = lcAvailCaption
			ENDIF
			
			
			lnMaxPO = MAX(lnMaxPO, lnAvailPO)
			
			IF lnMaxPO = lnAvailPO
				lnMaxPage    = lnAvailPage
				lcMaxCaption = lcAvailCaption
			ENDIF


			*** track the next and prev page order and no.
			IF lnAvailPO > lnCurrPO
				lnNextPO = MIN(lnNextPO, lnAvailPO)

				IF lnNextPO = lnAvailPO
					lnNextPage    = lnAvailPage
					lcNextCaption = lcAvailCaption
				ENDIF
			ENDIF

			IF lnAvailPO < lnCurrPO
				lnPrevPO = MAX(lnPrevPO, lnAvailPO)

				IF lnPrevPO = lnAvailPO
					lnPrevPage    = lnAvailPage
					lcPrevCaption = lcAvailCaption
				ENDIF
			ENDIF
		ENDIF
	ENDFOR


	*** if default values, assign fisrt and last page order and no. resp.
	IF lnPrevPO = -999999
		lnPrevPO      = lnMaxPO
		lnPrevPage    = lnMaxPage
		lcPrevCaption = lcMaxCaption
	ENDIF

	IF lnNextPO = 999999
		lnNextPO      = lnMinPO
		lnNextPage    = lnMinPage
		lcNextCaption = lcMinCaption
	ENDIF


	*** change the buttons caption
	.cmdPrevious.CAPTION = "<< " + lcPrevCaption
	.cmdNext.CAPTION     = lcNextCaption + " >>"


	*** hide buttons as required
	DO CASE
		CASE lcCurrCaption = lcPrevCaption
			*** current and the prev are same only one button
			THISFORM.cmdPrevious.MakeVisible(.F.)
			THISFORM.cmdNext.MakeVisible(.F.)

		CASE lcPrevCaption = lcNextCaption
			*** next and the prev are same no buttons
			THISFORM.cmdPrevious.MakeVisible(.F.)
			THISFORM.cmdNext.MakeVisible(.T.)

		OTHERWISE
			*** both buttons active
			THISFORM.cmdPrevious.MakeVisible(.T.)
			THISFORM.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"
			THISFORM.pgf.ACTIVEPAGE = lnPrevPO

		CASE UPPER(tcAdvanceTo) = "NEXT"
			THISFORM.pgf.ACTIVEPAGE = lnNextPO
	ENDCASE
ENDWITH
Regards
Bhavbhuti
___________________________________________
Softwares for Indian Businesses at:
http://venussoftop.tripod.com
___________________________________________
venussoftop@gmail.com
___________________________________________
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform