Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Arrays in VISUAL FOXPRO...

Status
Not open for further replies.

Markleber

Programmer
Aug 27, 2018
1
0
0
BR
Good night people...
I need help with two questions:

1a. Relying on the routine below:
SELECT linresul
DELETE ALL
PACK
APPEND FROM linresul.txt DELIMITED WITH CHARACTER "-"
GO vsor-1
SCATTER FIELDS linresul.d01, linresul.d02, linresul.d03, linresul.d04, linresul.d05, linresul.d06, linresul.d07, linresul.d08, linresul.d09 ,;
linresul.d10, linresul.d11, linresul.d12, linresul.d13, linresul.d14, linresul.d15 TO arr01

SELECT lifiltro
DELETE ALL
PACK
APPEND FROM linfingr.txt DELIMITED WITH CHARACTER "-"
replace ALL lifiltro.rep WITH 0

SELECT libackup
DELETE ALL
PACK

SELECT lifiltro
SET ORDER TO lifiltro
COUNT ALL TO vban
GO TOP
DO WHILE! EOF ()
WAIT WINDOW "PLEASE WAIT !!! Separating CONFIGURED LINES from the file into GROUPS and their REPTIMENTS ..." + ALLTRIM (STR (vreg)) "+" from "+ ALLTRIM (STR (vban)) NOWAIT
SCATTER FIELDS lifiltro.d01, lifiltro.d02, lifiltro.d03, lifiltro.d04, lifiltro.d05, lifiltro.d06, lifiltro.d07, lifiltro.d08, lifiltro.d09 ,;
lifiltro.d10, lifiltro.d11, lifiltro.d12, lifiltro.d13, lifiltro.d14, lifiltro.d15 TO arr02

FOR i = 1 TO 15
var1 = arr01
FOR j = 1 TO 15
var2 = arr02 [j]
IF var1 = var2
var3 = var3 + 1
ENDIF
ENDFOR
ENDFOR

IF var3> 0
replace lifiltro.rep WITH var3
ENDIF
var1 = 0
var2 = 0
var3 = 0

IF! EOF ()
SKIP
vreg = vreg + 1
ELSE
EXIT
ENDIF
ENDDO

Notice I have two scatters, both creating two arrays, right?
In this routine, FOR counts between the two arrays, the same quantities, however, one by one element until completing 15 and that in a file with more than 1 million records, is very time consuming.
Question:
There is how to count the elements without using FOR, counting the set for example:
ARRAY01 will have all 15 elements = 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15
ARRAY02 will have another 15 elements = 01 02 03 04 05 06 07 08 09 10 11 12 13 14 16
Note that FOR would count the 15 elements of each array between them, finding 14 equal between the two.
Can you count the elements of the arrays without using FOR, take the whole array01 and find the equals in array02?
With FOR it gets very slow ...

2a. On the basis that:
ARRAY03 will have all 15 elements = 01 02 03 07 08 10 05 06 09 04 11 12 13 14 15
How to make this array be sorted as follows = 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15?
 
There is no single line array element comparison, but your error is to nest two loops, you don't just compare elements with same index, you compare every element with every other. One loop is enough.
You have compobj() which works for two objects but only results in .T. or .F., not a count of matching elements.

Anyway, you have the potential to get faster by a factor of 15, when you only want to compare field1 with field1 etc. There's also no reason to copy array elements into variables first and in this case, using mdots (m.varname) for variable access will also pay.

If you really need to compare all elements with each other sorting will also not be a solution to only need to match element n of one with the same element of the other array, because you can have [highlight #FCE94F]1[/highlight] 2 [highlight #FCE94F]3[/highlight] 4 [highlight #FCE94F]5[/highlight] and [highlight #FCE94F]1[/highlight] [highlight #FCE94F]3[/highlight] [highlight #FCE94F]5[/highlight] 7 9 and that's still 3 matches and not only one. But sorting will allow to make less coparisons, ASORT is available for that.

If you had 15 values in two tables instead, you'd be able to make an inner join, but I guess transforming data to cursors to make use of the SQL solution would just take more time. Worth a try.


Bye, Olaf


Olaf Doschke Software Engineering
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top