×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Arrays in VISUAL FOXPRO...

Arrays in VISUAL FOXPRO...

Arrays in VISUAL FOXPRO...

(OP)
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 [i]
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?

RE: Arrays in VISUAL FOXPRO...

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 1 2 3 4 5 and 1 3 5 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
https://www.doschke.name

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close