Jump to content

Search as type


 Share

Recommended Posts

A while ago, I read from support section (well, maybe it was GUI section), that some ppl needed a program, that searches text as you type. There was suggested to make it with ListView, but I have used List more and it's easier to use. So here's the code:

#include <GuiConstants.au3>
Dim $buffer
$data = StringReplace(FileRead("data.txt"), @CRLF, "|")
Opt("GUIDataSeparatorChar", "|")
$split = StringSplit($data, "|")
GuiCreate("Search as typing", 179, 336,-1, -1)
$input = GuiCtrlCreateInput("", 10, 10, 160, 20)
$list = GUICtrlCreateList("", 10, 40, 160, 271)
GuiCtrlSetData($list, $data)
$case = GUICtrlCreateCheckbox("Case sensitive", 10, 311, 160, 20)
GuiSetState()
While 1
    $msg = GuiGetMsg()
    If $msg = $GUI_EVENT_CLOSE Then Exit
    If GuiCtrlRead($input) <> "" Then
    $savetext = GuiCtrlRead($input)
    For $i = 1 to $split[0]
        If GuiCtrlRead($case) = $GUI_CHECKED Then
            If StringLeft($split[$i], StringLen(GuiCtrlRead($input))) == $savetext Then
            $buffer &= $split[$i] & "|"
        EndIf
            Else
        If StringLower(StringLeft($split[$i], StringLen(GuiCtrlRead($input)))) == StringLower($savetext) Then
            $buffer &= $split[$i] & "|"
        EndIf
        EndIf
    Next
    $buffer = StringTrimRight($buffer, 1)
    GuiCtrlSetData($list, "")
    GuiCtrlSetData($list, $buffer)
    $buffer = ""
    ;========================================GUI Main Loop========================================
    Do
        $msg = GuiGetMsg()
    Select
    Case $msg = $GUI_EVENT_CLOSE
        Exit
    Case Else
        ;;;
    EndSelect
Until GuiCtrlRead($input) <> $savetext
;============================================GUI Main Loop End=====================================================
If GuiCtrlRead($input) = "" Then 
    GuiCtrlSetData($list, "")
    GuiCtrlSetData($list, $data)
    EndIf
        EndIf
WEnd

This script gets all words from "data.txt" file, so download it too for running my script.

EDIT: Fixed a little mistake in code.

data.txt

Edited by poisonkiller
Link to comment
Share on other sites

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
 Share

  • Recently Browsing   0 members

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