Contributed by Sam Cox.
Create a ListBox object named ListBox1. Make sure it’s variable is also called [ListBox1]. The list box must be sorted for the following to work, so execute ListBoxSort "ListBox1" before using the following.
Create a TextEntry object named TextEntry1. Make sure it’s variable is also called [TextEntry1].
Add the following code to the Text Change action of the TextEntry1 object:
ListBoxSize "ListBox1" "[ListBox1Size]"
StrLower "[TextEntry1]" "[TextEntry1LowerCase]"
Loop "1" "[ListBox1Size]" "[N]"
ListBoxGetItem "ListBox1" "[N]" "[Item]"
StrLower "[Item]" "[ItemLowerCase]"
SearchStr "[TextEntry1LowerCase]" "[ItemLowerCase]" "[Index]"
If "[Index]" "=" "1"
SetVar "[ListBox1]" "[Item]"
Run the code. Everytime you type a letter or, for that matter, any character including a backspace, the current value of [TextEntry1] is searched for in the ListBox1 object. If [TextEntry1] is found as the leading characters of any entry in ListBox1, that entry is displayed (highlighted) and you’re ready to type the next character.
1) The Suspend "True" and Suspend "False" actions allow the code to finish searching before another letter is typed.
2) I coded this directly in the Text Change action of TextEntry1 to run as fast as possible. It could have been written as a subroutine but would suffer a little from the overhead of calling that subroutine.
3) If while your program is running you add an entry to ListBox1, you must resort the list box.
What is Neobook?
Without ANY programming knowledge, you too can create and compile great full featured Windows Software, presentations, e-books, e-zines, catalogs and much more!
Simply put, it is a programming environment that allows you to create, compile and distribute royalty free applications of any kind. From beginners to advanced programmers, NeoBook RAD5 Pro has something for everybody. Try it free!