Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Need a fast way to go to an absolute index position...
Message
De
21/06/2004 14:46:01
 
 
À
21/06/2004 14:02:05
John Onysko
1 Edi Source, Inc.
Hudson, Ohio, États-Unis
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00915480
Message ID:
00915764
Vues:
14
Interesting.

I had put in an entry in the wish list (i think about a year ago) for a function i called "IndexRecno()" for exactly this reason. I too have a slider control on my forms and had the obvious problem that the slider position did not represent the correct position in the indexed table.

the whish got quit a bit of negative response, so i droped the arguing, since i could not convince people of the potential use. some of the argument was that this is not possible.

i have writen something in vfox which will give you the 'current' position in a table if an index is set - a new 'record number' so-to-speak based on the new indexed table. i run my sliders against a 63000 record table on a 100TBase Network and it's fast enough in my oppinion. could be faster of course if it where a native fox function - but, oh well.

as i slide the control this function gets called to ensure continues correct positioning in the control, it is supprisingly fast. i am sure this can be optimized. also in addition i think the calleing of that function can be cut down in my slider, but i havn't realy worked on that yet.

see if this helps you:
FUNC IndexRecNo
	* *** function to find the 'real' record number when an index (order) is set
	* *** the trick here is to know the details about rushmore tecknowlegy
	* *** rushmore only works if 2 things are given:
	* *** 1. set delete must be off. All records must be accessable for rushmore.
	* *** 2. the for clause expression must match EXACTLY the index.
	* ***    - i.e.: if the index is set to FistName + LastName you can not just search
	* ***            for a string with the length of the FirstName, you have got to have
	* ***            a string matching the length of the index.
	LPARA ;
		TableToCheck
	LOCAL ;
		IndexExp, ;
		IndRecCount, ;
		CurrIndexValue, ;
		OldRecNo, ;
		OldDele, ;
		OldLock, ;
		OldSele
	
	OldSele = SELECT()
	IF PCount() = 1
		SELE (TableToCheck)
	ENDIF
	IndRecCount		= 1
	IndexExp		= KEY()
	
	IF IsBlank(IndexExp)
		* *** no index (order) is set
		IF BETWEEN(RECNO(), 1, RECCOUNT()) .OR. RECNO() < 0
			IndRecCount = RECNO()
		ENDIF
	ELSE
		OldRecNo		= RECNO()
		CurrIndexValue	= EVAL(KEY())
		OldLock			= SET("lock")
		OldDele			= SET('dele')
		
		SET DELE ON
		SET LOCK OFF
		
		COUNT ;
			FOR &IndexExp <= CurrIndexValue ;
			TO IndRecCount
		
		SET DELE &OldDele
		SET LOCK &OldLock
		
		IF BETWEEN(OldRecNo, 1, RECCOUNT()) .OR. OldRecNo < 0
			IF OldRecNo <> RECNO()
				GO OldRecNo
			ENDIF
		ELSE
			GO TOP
		ENDIF
		
		IF TYPE("IndRecCount") <> "N" .OR. IndRecCount = 0
			IndRecCount = 1
		ENDIF
	ENDIF
	SELECT(OldSele)
	RETURN(IndRecCount)
ENDFUNC
>I knew somebody would ask for a reason -- I just didn't feel like typing it... :D
>
>I have a slider at the bottom of the window that allows rapid navigation -- it works great and people love it. Let's assume that there are 500,000 records in the table. I set the slider max to 500,000. When they move the slider around, it returns a value, say, 150,000.
>
>I then GO TOP, skip 149,000, and I am there. The slider is independent of the index order, so I have nothing to seek on. It is a physical identifier of where you are in the table. Again, it is very fast once you've "skipped" the entire table once.
>
>Make sense?
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform