>>I want to compare two arrays to see if one
>>is different. What is the best way?
>
>Try the following in a function. llresult will return .T. if the arrays are identical.
>
>LPARAMETERS parray1, parray2
>
>LOCAL llresult, lnlast1, lnlast2, lni
>lnlast1 = ALEN(parray1)
>lnlast2 = ALEN(parray2)
>lni = 0
>llresult = (lnlast1 = lnlast2)
>DO WHILE llresult AND lni < lnlast
> lni = lni + 1
> llresult = (parray1[lni] = parray2[lni])
>ENDDO
>RETURN llresult
>
>hth,
>
>George
I would change it slightly to improve performance by letting vfp do the incrementing and letting the user select starting the compare loop at the bottom if that is where the difference is most likely to occur (need speed!!):
LPARAMETERS parray1, parray2, top_bottom
if parameters() < 3
top_bottom = 0 && start at top (1)
endif
LOCAL lnlast1, lnlast2, lni
lnlast1 = ALEN(parray1)
lnlast2 = ALEN(parray2)
do case
case (lnlast1 != lnlast2)
return .f.
case top_bottom != 0
for lni = lnLast1 to 1 step -1
if (parray1[lni] != parray2[lni])
return .f.
endif
endfor
otherwise
for lni = 1 to lnLast1
if (parray1[lni] != parray2[lni])
return .f.
endif
endfor
endcase
RETURN .t.
Previous
Next
Reply
View the map of this thread
View the map of this thread starting from this message only
View all messages of this thread
View all messages of this thread starting from this message only