Selasa, 11 Oktober 2011

[ExcelVBA] Re: Binary Search Problem

 

David,
Not too late, I always like new ways of doing things. :-)

Your first suggestion worked well but when I tried to implement the Select Case, I get a Select Case without End Case when it reaches the End Function at Case = 0.

Scott

--- In ExcelVBA@yahoogroups.com, "david braithwaite" <dbraithwaite@...> wrote:
>
> Hi
>
> Hope it is not too late to way in. There is an easy way to solve your
> problem.
>
>
>
> In the binary search, instead of using the statement:
>
>
>
> If (strArray(lngMiddle) < strSearch) .
>
>
>
> Use the statement
>
>
>
> If strcomp(strArray(lngMiddle),strSearch,vbTextCompare) & bolInverseOrder <
> 0 then
>
>
>
> (the vbtextcompare will do the same normalization of the strings as the
> Excel sort routine)
>
>
>
> And
>
>
>
> I got 85/85 which you reported was what the long running Find routine gave.
>
>
>
> (you can also save a compare per loop by using
>
>
>
> Select case strcomp(strArray(lngMiddle),strSearch,vbTextCompare) &
> bolInverseOrder
>
> Case =0 : binarysearch = lngmiddle: end function
>
> Case < 0
>
> Lngmiddle = lngMiddle+1
>
> Case > 0
>
> lngMiddle = lngMiddle-1
>
> End select
>
>
>
>
>
> DAVIDB
>
>
>
>
>
>
>
> [Non-text portions of this message have been removed]
>

__._,_.___
Recent Activity:
----------------------------------
Be sure to check out TechTrax Ezine for many, free Excel VBA articles! Go here: http://www.mousetrax.com/techtrax to enter the ezine, then search the ARCHIVES for EXCEL VBA.

----------------------------------
Visit our ExcelVBA group home page for more info and support files:
http://groups.yahoo.com/group/ExcelVBA

----------------------------------
More free tutorials and resources available at:
http://www.mousetrax.com

----------------------------------
MARKETPLACE

Stay on top of your group activity without leaving the page you're on - Get the Yahoo! Toolbar now.

.

__,_._,___

Tidak ada komentar:

Posting Komentar