vazagothic
Programmer
Hello,
I've encountered a weird behaviour of VFP 8.0. I do not know how to explain it, but code which was working just fine under 6.0 no longer performs as it should with the VFP 8.0.
The purpose of the code is to get all unique values from the table (without using SQL SELECT) - it uses the table's index to move between different values.
It jumps to the first occurence of certain value, then moves back one record (to get another unique value), next jumps to the first occurence of this value .. and so on
Here's the code - I've modified it a bit, so it would work as a whole piece:
*** CODE STARTS HERE ***
[red]
scNameFile = "Names_MM"
USE names_MM
SET ORDER TO cty_owner
SELECT (scNameFile)
GO TOP
* Get the first value from table
lcCountyValue = county
* Scan the entire table using INDEX value
DO WHILE .T.
* Show record number (just for TESTING)
? RECNO()
* Scan in the backward order - which finds the last matching value
SEEK lcCountyValue ORDER cty_owner DESCENDING
IF FOUND()
* Add only NON-EMPTY values
IF !EMPTY(lcCountyValue)
? lcCountyValue
ENDIF
SELECT (scNameFile)
* Move to the previous value and remember it
SKIP -1
* Check if current county is the same as the previous one found ..
IF lcCountyValue = county
EXIT
ENDIF
lcCountyValue = county
ELSE
EXIT
ENDIF
ENDDO
[/red]
*** CODE ENDS HERE ***
It seems that VFP 8 no longer follows the index value while using SKIP +/- 1.
The output with VFP6 looks like:
[blue]
8385
7667
MINNEHAHA
9180
ALAMEDA
9158
ALBANY
6247
ARAPAHOE
[/blue]
etc
While the VFP8 leaves the loop just after showing "[blue]8385[/blue]".
How should I modify the above code so it would work fine under VFP8 ?
I should mention that using [red]SELECT DISTINCT county FROM names_mm INTO CURSOR tmp[/red] is quite useless. SQL SELECT takes more than 10 times longer for a table 500k records big, than the method shown above.
I've encountered a weird behaviour of VFP 8.0. I do not know how to explain it, but code which was working just fine under 6.0 no longer performs as it should with the VFP 8.0.
The purpose of the code is to get all unique values from the table (without using SQL SELECT) - it uses the table's index to move between different values.
It jumps to the first occurence of certain value, then moves back one record (to get another unique value), next jumps to the first occurence of this value .. and so on
Here's the code - I've modified it a bit, so it would work as a whole piece:
*** CODE STARTS HERE ***
[red]
scNameFile = "Names_MM"
USE names_MM
SET ORDER TO cty_owner
SELECT (scNameFile)
GO TOP
* Get the first value from table
lcCountyValue = county
* Scan the entire table using INDEX value
DO WHILE .T.
* Show record number (just for TESTING)
? RECNO()
* Scan in the backward order - which finds the last matching value
SEEK lcCountyValue ORDER cty_owner DESCENDING
IF FOUND()
* Add only NON-EMPTY values
IF !EMPTY(lcCountyValue)
? lcCountyValue
ENDIF
SELECT (scNameFile)
* Move to the previous value and remember it
SKIP -1
* Check if current county is the same as the previous one found ..
IF lcCountyValue = county
EXIT
ENDIF
lcCountyValue = county
ELSE
EXIT
ENDIF
ENDDO
[/red]
*** CODE ENDS HERE ***
It seems that VFP 8 no longer follows the index value while using SKIP +/- 1.
The output with VFP6 looks like:
[blue]
8385
7667
MINNEHAHA
9180
ALAMEDA
9158
ALBANY
6247
ARAPAHOE
[/blue]
etc
While the VFP8 leaves the loop just after showing "[blue]8385[/blue]".
How should I modify the above code so it would work fine under VFP8 ?
I should mention that using [red]SELECT DISTINCT county FROM names_mm INTO CURSOR tmp[/red] is quite useless. SQL SELECT takes more than 10 times longer for a table 500k records big, than the method shown above.