LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Search 1D Array with first occurance

Solved!
Go to solution

All,

 

I am trying to develop a subVI that loads in the MS Outlook Address Book into a MultiColumn Listbox. There are hundreds of names in this address book so I would like to use a feature that when a user starts typing in a name, it will take the user to the specific record in the listbox. I want this to start at the beginning of the the Name field but I am having a hard time. I would appreciate some guidance.

 

Thanks,

Eric

Download All
0 Kudos
Message 1 of 16
(3,430 Views)

If you keep the names in a shift register, then you just have to do a search for the first item that is greater or equal to the typed in string.  That will give you the index to set your listbox to.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 2 of 16
(3,413 Views)

It looks like you've thought about doing the search as each key gets typed in the Search name, so the problem comes down (I suppose) to optimizing the search process.

 

I notice that you have a sorted list to search.  The fact that it is also fairly large can probably work in your favor.  Each letter that you type decreases the size of your search space (assuming you are using case-insensitive searches) by roughly 1/26 (I'm ignoring numbers and symbols for the sake of argument), and if you know the first two letters, you have reduced your space by 1/676.

 

Do a pass through your table of names, noting the index where the first "aa", "ab", "ac", "ad", etc. entries are located.  After the first two letters are typed, you can immediately say "I need to search between entries 356 and 372" (the matching indices of your digram and the next entry).  If you find a match for the third letter, say at entry 363, you can show it, and remember it as the starting entry for the next search when the fourth letter is typed; if there is no match, you're done and can do whatever you need to do with entries that are not on your list.

 

How does that sound to you?

 

Bob Schor

 

0 Kudos
Message 3 of 16
(3,400 Views)

I am not following what your getting at. Isn't autoindexing the Name Column in the For Loop (in the "Search" case) enough?

0 Kudos
Message 4 of 16
(3,395 Views)

Bob, you are correct that the Names are already sorted. I am guessing this is done already by the Outlook Address Book. Maybe a visual example would help drive home what you guys are getting at.

 

Eric

0 Kudos
Message 5 of 16
(3,391 Views)

So my algorithm should be quick and good.  I'd probably make two "indexing" arrays, one of size 26 (again, I'm just considering lower-case letters, but you can easily add numbers and symbols) for the first character, one of 676 for digrams (first two letters), and then a simple linear search from where you are for each additional letter.  There is a "cost" in making the two index arrays, but you do this once for your list and can use it over and over (if you're doing this a lot, you can consider saving the index to a file -- if your list doesn't change, or changes "slowly", your index will remain pretty good).

 

BS

0 Kudos
Message 6 of 16
(3,381 Views)

I did a bunch of simplifying of your code.  See if this does what you want.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 7 of 16
(3,377 Views)

Crossrulz,

 

I would have liked to start at the beginning of the Name column and worked my way to the right. So, for example, if a users name is Sarah, and the first letter entered is/was an S (or s), it should find the first charaecter that starts with an S. Same thing happens when a user enters Sa, Sar, and so on.

 

Right now, it finds the first letter anywhere in the Name field (the first column). When I type an E (the start of my name), it goes to the third row (visually).

 

Eric

0 Kudos
Message 8 of 16
(3,362 Views)

Then change the comparison to be an Equal To 0 instead of a Greater Or Equal To 0.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 9 of 16
(3,353 Views)

Nope. Still doesn't work. It just loops through the entire array and the multicolumn listbox ends up at the end. I think that using Equal to Zero tries to find an exact match. That is not what I want.

 

Maybe I am not being clear. What I am after for is a wildcard search on the 1D array. After the characters are entered, like Eri, I want a wildcard search for any other characters after the initial characters are entered into the Search string control.

 

For example:

 

Amy

Brian

Blaine

Eric A

Eric D

Eric S

Jim

Sarah

etc.

 

Using the search criteria above, it should find item 3 as the item to highlight.

0 Kudos
Message 10 of 16
(3,337 Views)