Jump to content

Recommended Posts

Posted

AutoIt 3.0.94 (latest unstable) - Win XP Pro sp1

; sample arrays; real ones are bigger
$FUNCS = StringSplit("funcA|funcB|funcC|funcD|funcE" , "|")
$SPECS = StringSplit("descA|descB|descC|descD|descE" , "|")

MsgBox(4096,"", lookup("funcD") )
Exit

Func lookup($keyword)  ; binary search that returns element
   Local $lo = 1, $i, $hi = UBound($FUNCS)-1
      
   While ($lo <= $hi)
      $i = Round( ($lo+$hi)/2 )
      If $keyword > $FUNCS[$i] Then
         $lo = $i + 1
      ElseIf
         $hi = $i - 1
      Else
         Return $SPECS[$i]
      EndIf
   WEnd
   Return ""
EndFunc
Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig!
Posted (edited)

Bad use of ElseIf

ElseIf

; sample arrays; real ones are bigger
$FUNCS = StringSplit("funcA|funcB|funcC|funcD|funcE" , "|")
$SPECS = StringSplit("descA|descB|descC|descD|descE" , "|")

MsgBox(4096,"", lookup("funcD") )
Exit

Func lookup($keyword); binary search that returns element
  Local $lo = 1, $i, $hi = UBound($FUNCS)-1
  Local $lo = 1, $i, $hi = $FUNCS[0]-1
     
  While ($lo <= $hi)
     $i = Round( ($lo+$hi)/2 )
     If $keyword > $FUNCS[$i] Then
        $lo = $i + 1
     ElseIf $keyword < $FUNCS[$i] Then; not sure what you wanted to do
        $hi = $i - 1
     Else
        Return $SPECS[$i]
     EndIf
  WEnd
  Return ""
EndFunc

edit... oops, I see you already found it.

Edited by scriptkitty

AutoIt3, the MACGYVER Pocket Knife for computers.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...