CyberSlug Posted February 18, 2004 Share Posted February 18, 2004 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! Link to comment Share on other sites More sharing options...
CyberSlug Posted February 18, 2004 Author Share Posted February 18, 2004 EDIT: Oops, I forgot the ElseIf clause. Error message was quite unhelpful Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig! Link to comment Share on other sites More sharing options...
scriptkitty Posted February 18, 2004 Share Posted February 18, 2004 (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 February 18, 2004 by scriptkitty AutoIt3, the MACGYVER Pocket Knife for computers. Link to comment Share on other sites More sharing options...
CyberSlug Posted February 18, 2004 Author Share Posted February 18, 2004 Thanks for posting Scriptkitty. I'm happy to know someone was trying to help If I hadn't found the bug when I did, your post would probably have saved me hours of searching! Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig! Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now