LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Searching Lists in the Programmer's toolbox

I have a Programmer's toolbox List of structures. When I want to find an item by one of the structure's fields, must I create a key with all of the structure's fields filled in exactly as it appears in the list, or can I search for a match of a single field? Can this be done with the "Compare" callback or must I go through the list manually myself?
0 Kudos
Message 1 of 2
(2,684 Views)
I have used sorting and searching functions for arrays of structures, instead of lists of structures; these are not exactly the same, but I assume the behaviour be the same.
I used BinSearch to search the array (the same function used in ListBinSearch provided by the toolbox): the third parameter to both functions is the name of a comparison function used to compare elements in the list.
Since you must build your own comparison function, you can customize it according to your needs (that is, testing the exact field you need in the structure).

The structure must be sorted previous to using ListBinSearch, but sorting uses the same comparison function as searching, so it's not a problem.

Hope this helps
Roberto


Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
Message 2 of 2
(2,684 Views)