I needed to find unique values in a large list containing many
instances of the same values.
Here is what I came up with.
This program extracts the unique values with only one pass
through the large list.
(I used it to extract unique customer record numbers from a large
random access file.)
John Tate
------------------
[This message has been edited by John Tate (edited December 02, 2006).]
instances of the same values.
Here is what I came up with.
This program extracts the unique values with only one pass
through the large list.
(I used it to extract unique customer record numbers from a large
random access file.)
John Tate
Code:
FUNCTION PBMAIN() DATA "A","B","C","A","D","B","C","C","A","B","D" LOCAL list() AS STRING, Items() AS STRING LOCAL I AS LONG, J AS LONG ,K AS LONG REDIM list(1 :DATACOUNT):REDIM items(1 :DATACOUNT) FOR I = 1 TO DATACOUNT List(I)= READ$(i) NEXT 'now have list in array items(1)= List(1) 'put first item in items array 'to have first item for comparison K = 1 'there is only one item to compare to FOR I = 1 TO DATACOUNT 'compare large list to unique list FOR J = 1 TO K IF List(i) = items(J) THEN EXIT FOR 'if a match, then List variable already in items list NEXT IF J > K THEN INCR K:Items(K) = List(i) 'if true, then no match was found- 'add new unique item to items list NEXT 'items list grows only when no match is found REDIM PRESERVE items(1:K) FOR I = 1 TO K PRINT Items(i) NEXT WAITKEY$ END FUNCTION 'end of main
------------------
[This message has been edited by John Tate (edited December 02, 2006).]
Comment