# LabVIEW

cancel
Showing results for
Did you mean:

Solved!
Go to solution

## Search 1D Array with first occurance

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

Message 1 of 16
(3,433 Views)

## Re: Search 1D Array with first occurance

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.

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
Message 2 of 16
(3,416 Views)

## Re: Search 1D Array with first occurance

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

Message 3 of 16
(3,403 Views)

## Re: Search 1D Array with first occurance

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

Message 4 of 16
(3,398 Views)

## Re: Search 1D Array with first occurance

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

Message 5 of 16
(3,394 Views)

## Re: Search 1D Array with first occurance

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

Message 6 of 16
(3,384 Views)

## Re: Search 1D Array with first occurance

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

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
Message 7 of 16
(3,380 Views)

## Re: Search 1D Array with first occurance

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

Message 8 of 16
(3,365 Views)

## Re: Search 1D Array with first occurance

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

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
Message 9 of 16
(3,356 Views)

## Re: Search 1D Array with first occurance

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.

Message 10 of 16
(3,340 Views)