Jump to content
Kovacic

Trying to make Autocomplete like Google search in a text box

Recommended Posts

Kovacic

I am taking some idea from here:

'?do=embed' frameborder='0' data-embedContent>>

 

But what I am looking to accomplish is simple, I want to have an input box with a hidden input box below it. I will also have a defined list of items. When the text box has any value in it that does not directly equal an item in the pre defined list, the edit box should show. and populate suggested items based on whats being typed which I will do that part later, should be easy.

I am stuck on a simple portion which should be easy and i'm not sure why I am having trouble with it.  The way thr code below should work is, as long as there is a value in the Input box, the edit box will appear, if there is no value in the input box, the edit box should be hidden. 

here is what I have so far:

#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
$Form1 = GUICreate("Form1", 615, 438, 192, 124)
$Input1 = GUICtrlCreateInput("", 64, 72, 313, 21)
$Edit1 = GUICtrlCreateEdit("", 64, 96, 313, 177)
GUISetState(@SW_SHOW)
GUICtrlSetState($Edit1, $GUI_HIDE)

While 1
$words = GUICtrlRead($Input1)
If $words NOT = "" then
GUICtrlSetState($Edit1, $GUI_SHOW)
else
GUICtrlSetState($Edit1, $GUI_HIDE)
endif
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

    EndSwitch
WEnd

func flopdrop()
            If BitAnd($Edit1,2) AND $words = "" Then
            GUICtrlSetState($Edit1, $GUI_HIDE)
             Else
             GUICtrlSetState($Edit1, $GUI_SHOW)
            EndIf
endfunc

the problem with this is a nasty flicker when you move the mouse or do anything else. I will get rid of the scroll bars too, but thats once I solve this flicker issue. I know its happening because I have the check being performed within the While statement, but I can't think of any other way to do it.. I even tried using a timer to only check once every few seconds, but that didn't seem to work either:

If $words NOT = "" AND (@SEC = 00 OR 10 OR 20 OR 30 OR 40 OR 50) AND (@MSEC < 20)) Then
  ; Blah blah blah

endIf

Does anyone have any thoughts or has anyone been able to do this?

Thanks in advance!!


C0d3 is P0etry( ͡° ͜ʖ ͡°)

Share this post


Link to post
Share on other sites
Rogue5099

Its flickering due to GuiCtrlSetState constantly. Best option would be to get the state and if its already shown then skip showing it.

Share this post


Link to post
Share on other sites
Kovacic

You could start with >this script from martin.

 

I actually did try that one, but it doesn't do what I am looking for...  I was hoping for a drop down you could click on if you see the object you want.

 

Its flickering due to GuiCtrlSetState constantly. Best option would be to get the state and if its already shown then skip showing it.

 

I did have that in an If statement, but it was still flickering.


C0d3 is P0etry( ͡° ͜ʖ ͡°)

Share this post


Link to post
Share on other sites
Kovacic

Im going to try combining martins script with mine, I like the idea of just using a label, because it can be easily clicked on to finish the auto complete... If it works, I'll post the final code for others to use and give Martin credit.


C0d3 is P0etry( ͡° ͜ʖ ͡°)

Share this post


Link to post
Share on other sites
Kovacic

I am so close I can taste it!! I now have a list box pop up under the input box with some search options, I just want to make it so if you click on the option you want, it populates... OR maybe be able to press the down arrow until you find the option you want.. 

I think a few people in the past were asking for something like this so it might be a good find if we can make it work.. 

Here is the latest and greatest (it normally pulls from SQL, but I put in a mock line to emulate results of random words):

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>
#include <ComboConstants.au3>


#cs
$conn = ObjCreate( "ADODB.Connection" )
$DSN = "All my SQL connection stuff"
$conn.Open($DSN)


$rs = ObjCreate("ADODB.RecordSet")

$rs.Open("SELECT Serial FROM tbl_Manual", $conn)
;$rs.Open("SELECT TOP 20 Serial FROM tbl_Manual", $conn)
If $RS.RecordCount Then
    While Not $RS.EOF
    local $MyVal = $MyVal & "|" & StringStripWS($rs.Fields("serial").value,8)
        $RS.MoveNext
    WEnd
EndIf

$RS.Close
$conn.close
#ce
$MyVal = "fracturing|enzygotic|bondwoman|mealtime|miketime|kimball|kiteball|unreelable|aruspices|prevoted|punt|taxis"

local $MyVal2 = $MyVal
$MyVal = StringSplit($MyVal,"|")

GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")

$gui = GUICreate("My GUI edit")

$IP = GUICtrlCreateInput("", 10, 18, 200, 22)
$Edit1 = GUICtrlCreateList("", 10, 40, 200, 177)
GUICtrlSetState($Edit1, $GUI_Hide)

GUISetState()


While 1
    $msg = GUIGetMsg()
    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
WEnd



Func WM_COMMAND($hWnd, $msg, $wParam, $lParam)
    $nNotifyCode = BitShift($wParam, 16)
    $nID = BitAND($wParam, 0x0000FFFF)
    If $nID = $IP Then
        $hCtrl = $lParam
        If $nNotifyCode = $EN_CHANGE Then
            $txt = GUICtrlRead($IP)
            For $n = 1 To UBound($MyVal) - 1
                If StringCompare(StringLeft($MyVal[$n], StringLen($txt)), $txt) = 0 Then
                    GUICtrlSetData($Edit1, $MyVal[$n])
                    if GUICtrlRead($IP) then
                    GUICtrlSetState($Edit1, $GUI_show)
                    else
                    GUICtrlSetState($Edit1, $GUI_Hide)
                    endif
                    
                    ExitLoop
                EndIf
            Next
            
        EndIf
    EndIf
    Return $GUI_RUNDEFMSG
EndFunc  ;==>WM_COMMAND

As usual, any and all comments, hints, tips, spelling corrections, suggestions are welcome!


C0d3 is P0etry( ͡° ͜ʖ ͡°)

Share this post


Link to post
Share on other sites
JohnOne

I think this piece of code in callback function determines that the message came from input,

If $nID = $IP Then
        $hCtrl = $lParam
        If $nNotifyCode = $EN_CHANGE Then
            $txt = GUICtrlRead($IP)
            For $n = 1 To UBound($MyVal) - 1
                If StringCompare(StringLeft($MyVal[$n], StringLen($txt)), $txt) = 0 Then
                    GUICtrlSetData($Edit1, $MyVal[$n])
                    if GUICtrlRead($IP) then
                    GUICtrlSetState($Edit1, $GUI_show)
                    else
                    GUICtrlSetState($Edit1, $GUI_Hide)
                    endif

                    ExitLoop
                EndIf
            Next

        EndIf
    EndIf

you might have to code another condition for your list box.

  • Like 1

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Share this post


Link to post
Share on other sites
Kovacic

I think this piece of code in callback function determines that the message came from input,

If $nID = $IP Then
        $hCtrl = $lParam
        If $nNotifyCode = $EN_CHANGE Then
            $txt = GUICtrlRead($IP)
            For $n = 1 To UBound($MyVal) - 1
                If StringCompare(StringLeft($MyVal[$n], StringLen($txt)), $txt) = 0 Then
                    GUICtrlSetData($Edit1, $MyVal[$n])
                    if GUICtrlRead($IP) then
                    GUICtrlSetState($Edit1, $GUI_show)
                    else
                    GUICtrlSetState($Edit1, $GUI_Hide)
                    endif

                    ExitLoop
                EndIf
            Next

        EndIf
    EndIf

you might have to code another condition for your list box.

 

 

That part seems to be working, so it only shows the list box if there is something in the input box... What i'm struggling with now is the SQL query. When I do a search, and try to move the data returned by the SQL Query, only 1 or 2 records come back, but if I run the same query in SQLCMD, I get several returns... The issue seems to be in here:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>
#include <ComboConstants.au3>
#include <Array.au3>

global $MyVal

$conn = ObjCreate( "ADODB.Connection" )
$DSN = "DRIVER={SQL Server};SERVER=1.2.3.4;DATABASE=inventory;uid=inventory;pwd=MyPassWord;"
$conn.Open($DSN)
$rs = ObjCreate("ADODB.RecordSet")
;$rs.Open("SELECT Serial FROM tbl_Manual", $conn); To grab everything
$rs.Open("SELECT TOP 20 Serial FROM tbl_Manual", $conn); to grab only 20 results just for testing
While $rs.eof <> True
;ConsoleWrite($rs.Fields("Serial").Value & @CRLF); <~~ this works to bring data to the console
For $x In $rs.Fields
$MyVal = $MyVal & $x.name & "|"; <~~ This is supposed to populate $MyVal with the results with a pipe between them
Next
$x.MoveNext
Wend
$RS.Close
$conn.close
;$MyVal = "fracturing|enzygotic|bondwoman|mealtime|miketime|kimball|kiteball|unreelable|aruspices|prevoted|punt|taxis"; I only use this for demoing the input box with random word values.
$MyVal = StringSplit($MyVal,"|"); Splits the string at the pipe to make an array
local $MyVal2 = $MyVal
Msgbox(0,"MyVal", $MyVal)
_ArrayDisplay($MyVal, "2"); Just so I can see what comes back, for testing only. Ill remove it on the final script


GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")

$gui = GUICreate("My GUI edit")

$IP = GUICtrlCreateInput("", 10, 18, 200, 22)
$Edit1 = GUICtrlCreateList("", 10, 40, 200, 177)
GUICtrlSetLimit(-1, 20)
GUICtrlSetState($Edit1, $GUI_Hide)

GUISetState()


While 1
    $msg = GUIGetMsg()
    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
WEnd



Func WM_COMMAND($hWnd, $msg, $wParam, $lParam)
    $nNotifyCode = BitShift($wParam, 16)
    $nID = BitAND($wParam, 0x0000FFFF)
    If $nID = $IP Then
        $hCtrl = $lParam
        If $nNotifyCode = $EN_CHANGE Then
            $txt = GUICtrlRead($IP)
            For $n = 1 To UBound($MyVal) - 1
            ;Msgbox(0,"Records found: " & $n, $MyVal[$n])
                If StringCompare(StringLeft($MyVal[$n], StringLen($txt)), $txt) = 0 Then
                    GUICtrlSetData($Edit1, $MyVal[$n])
                    
                    if GUICtrlRead($IP) then
                    GUICtrlSetState($Edit1, $GUI_show)
                    else
                    GUICtrlSetState($Edit1, $GUI_Hide)
                    endif
                    
                    ExitLoop
                EndIf
            Next
            
        EndIf
    EndIf
    Return $GUI_RUNDEFMSG
EndFunc  ;==>WM_COMMAND

C0d3 is P0etry( ͡° ͜ʖ ͡°)

Share this post


Link to post
Share on other sites
Melba23

Kovacic,

Does this help at all? :huh:

#include <GUIConstantsEx.au3>
#include <Array.au3>
#Include <GuiListBox.au3>

Global $hGUI, $hInput, $hList, $sPartialData, $asKeyWords[100]

; Create list full of random 5 character "words"
Keywords()

$hGUI = GUICreate("Example", 200, 400)
$hInput = GUICtrlCreateInput("", 5, 5, 190, 20)
$hList = GUICtrlCreateList("", 5, 30, 190, 325, BitOR(0x00100000, 0x00200000))
$hButton = GUICtrlCreateButton("Read", 60, 360, 80, 30)
$hUP = GUICtrlCreateDummy()
$hDOWN = GUICtrlCreateDummy()
$hENTER = GUICtrlCreateDummy()
GUISetState(@SW_SHOW, $hGUI)

; Set accelerators for Cursor up/down and Enter
Dim $AccelKeys[3][2]=[["{UP}", $hUP], ["{DOWN}", $hDOWN], ["{ENTER}", $hENTER]]
GUISetAccelerators($AccelKeys)

$sCurr_Input = ""
$iCurrIndex = -1

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $hList
            $sChosen = GUICtrlRead($hList)
            If $sChosen <> "" Then GUICtrlSetData($hInput, $sChosen)
        Case $hButton
            If $sPartialData <> "" Then
                $sFinal = GUICtrlRead($hInput)
                If _ArraySearch($asKeyWords, $sFinal) > 0 Then
                    MsgBox(0, "Chosen", $sFinal)
                EndIf
            EndIf
        Case $hUP
            If $sPartialData <> "" Then
                $iCurrIndex -= 1
                If $iCurrIndex < 0 Then $iCurrIndex = 0
                _GUICtrlListBox_SetCurSel($hList, $iCurrIndex)
            EndIf
        Case $hDOWN
            If $sPartialData <> "" Then
                $iTotal = _GUICtrlListBox_GetCount($hList)
                $iCurrIndex += 1
                If $iCurrIndex > $iTotal - 1 Then $iCurrIndex = $iTotal - 1
                _GUICtrlListBox_SetCurSel($hList, $iCurrIndex)
            EndIf
        Case $hENTER
            If $iCurrIndex <> -1 Then
                $sText = _GUICtrlListBox_GetText($hList, $iCurrIndex)
                GUICtrlSetData($hInput, $sText)
                $iCurrIndex = -1
                _GUICtrlListBox_SetCurSel($hList, $iCurrIndex)
            EndIf
    EndSwitch

    ; If input has changed, refill list with matching items
    If GUICtrlRead($hInput) <> $sCurr_Input Then
        CheckInputText()
        $sCurr_Input = GUICtrlRead($hInput)
    EndIf

WEnd

Func CheckInputText()

    $sPartialData = "|" ; Start with delimiter so new data always replaces old
    Local $sInput = GUICtrlRead($hInput)
    If $sInput <> "" Then
        For $i = 0 To 99
            If StringInStr($asKeyWords[$i], $sInput) <> 0 Then $sPartialData &= $asKeyWords[$i] & "|"
        Next
        GUICtrlSetData($hList, $sPartialData)
    EndIf
EndFunc   ;==>CheckInputText

Func Keywords()

    Local $sData
    For $i = 0 To 99
        $asKeyWords[$i] = Chr(Random(65, 90, 1)) & Chr(Random(65, 90, 1)) & Chr(Random(65, 90, 1)) & Chr(Random(65, 90, 1))
        $sData &= $asKeyWords[$i] & "|"
    Next
    GUICtrlSetData($hList, $sData)
    $iCurrIndex = -1
    _GUICtrlListBox_SetCurSel($hList, $iCurrIndex)

EndFunc   ;==>Keywords
Please ask if anything is unclear. :)

M23

  • Like 1

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
Kovacic

Kovacic,

Does this help at all? :huh:

#include <GUIConstantsEx.au3>
#include <Array.au3>
#Include <GuiListBox.au3>

Global $hGUI, $hInput, $hList, $sPartialData, $asKeyWords[100]

; Create list full of random 5 character "words"
Keywords()

$hGUI = GUICreate("Example", 200, 400)
$hInput = GUICtrlCreateInput("", 5, 5, 190, 20)
$hList = GUICtrlCreateList("", 5, 30, 190, 325, BitOR(0x00100000, 0x00200000))
$hButton = GUICtrlCreateButton("Read", 60, 360, 80, 30)
$hUP = GUICtrlCreateDummy()
$hDOWN = GUICtrlCreateDummy()
$hENTER = GUICtrlCreateDummy()
GUISetState(@SW_SHOW, $hGUI)

; Set accelerators for Cursor up/down and Enter
Dim $AccelKeys[3][2]=[["{UP}", $hUP], ["{DOWN}", $hDOWN], ["{ENTER}", $hENTER]]
GUISetAccelerators($AccelKeys)

$sCurr_Input = ""
$iCurrIndex = -1

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $hList
            $sChosen = GUICtrlRead($hList)
            If $sChosen <> "" Then GUICtrlSetData($hInput, $sChosen)
        Case $hButton
            If $sPartialData <> "" Then
                $sFinal = GUICtrlRead($hInput)
                If _ArraySearch($asKeyWords, $sFinal) > 0 Then
                    MsgBox(0, "Chosen", $sFinal)
                EndIf
            EndIf
        Case $hUP
            If $sPartialData <> "" Then
                $iCurrIndex -= 1
                If $iCurrIndex < 0 Then $iCurrIndex = 0
                _GUICtrlListBox_SetCurSel($hList, $iCurrIndex)
            EndIf
        Case $hDOWN
            If $sPartialData <> "" Then
                $iTotal = _GUICtrlListBox_GetCount($hList)
                $iCurrIndex += 1
                If $iCurrIndex > $iTotal - 1 Then $iCurrIndex = $iTotal - 1
                _GUICtrlListBox_SetCurSel($hList, $iCurrIndex)
            EndIf
        Case $hENTER
            If $iCurrIndex <> -1 Then
                $sText = _GUICtrlListBox_GetText($hList, $iCurrIndex)
                GUICtrlSetData($hInput, $sText)
                $iCurrIndex = -1
                _GUICtrlListBox_SetCurSel($hList, $iCurrIndex)
            EndIf
    EndSwitch

    ; If input has changed, refill list with matching items
    If GUICtrlRead($hInput) <> $sCurr_Input Then
        CheckInputText()
        $sCurr_Input = GUICtrlRead($hInput)
    EndIf

WEnd

Func CheckInputText()

    $sPartialData = "|" ; Start with delimiter so new data always replaces old
    Local $sInput = GUICtrlRead($hInput)
    If $sInput <> "" Then
        For $i = 0 To 99
            If StringInStr($asKeyWords[$i], $sInput) <> 0 Then $sPartialData &= $asKeyWords[$i] & "|"
        Next
        GUICtrlSetData($hList, $sPartialData)
    EndIf
EndFunc   ;==>CheckInputText

Func Keywords()

    Local $sData
    For $i = 0 To 99
        $asKeyWords[$i] = Chr(Random(65, 90, 1)) & Chr(Random(65, 90, 1)) & Chr(Random(65, 90, 1)) & Chr(Random(65, 90, 1))
        $sData &= $asKeyWords[$i] & "|"
    Next
    GUICtrlSetData($hList, $sData)
    $iCurrIndex = -1
    _GUICtrlListBox_SetCurSel($hList, $iCurrIndex)

EndFunc   ;==>Keywords
Please ask if anything is unclear. :)

M23

 

 

This helps very much!! Thank you!! I can use the portion where you click on the result to have it populate the input box! too awesome thanks!!

 

This SQL portion is eating me alive...  this is the spot I'm stuck with at the moment... 

...

If $RS.RecordCount Then
    While Not $RS.EOF
    local $MyVal = $MyVal & StringStripWS($rs.Fields("Serial").value,8) & "|"
        $RS.MoveNext
    WEnd
EndIf

...

Which is just a piece of the code i posted earlier.. I know I'm doing something wrong here...    when I execute the query in SQLCMD I get a nice array of data back. I am trying to now move that to an array which will essentially populate the word list. This way, once an object is chosen, its full details will come up..

when seems to be happening is, the array that is being returned is only the last record being returned from SQL... 

i.e.

SQL returns:

MyComputers

----------------------

compu1

compu2

compu3

compu4

compu5

compu6

compu7

compu8

compu9

 

when I dump the array, im getting:

[0] = "2"

[1] = "compu9"

[2] = ""

 

I have a feeling its where I dump the SQL into the variable, but all the research I have done shows it should be correct.

 

C0d3 is P0etry( ͡° ͜ʖ ͡°)

Share this post


Link to post
Share on other sites
Kovacic

MISSION ACCOMPLISHED!  :bike:

 

Except for the SQL stuff I took out, this has now reached awesome!

Enjoy!

:thumbsup:

#include <GUIConstantsEx.au3>
#include <Array.au3>
#Include <GuiListBox.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>
#include <ComboConstants.au3>
Global $hGUI
Global $hInput
Global $hList
Global $sPartialData
Global $output = ''
Local $conn = ObjCreate( "ADODB.Connection" )
Local $DSN = "DRIVER={SQL Server};SERVER=MyServer;DATABASE=MyDB;uid=MyUID;pwd=MyPaSsWoRd;"



SQLQuery()
$hGUI = GUICreate("Example", 200, 400)
$hInput = GUICtrlCreateInput("", 5, 5, 190, 20)
$hList = GUICtrlCreateList("", 5, 30, 190, 225, BitOR(0x00100000, 0x00200000))
GUICtrlSetLimit(-1, 20)
GUICtrlSetState($hList, $GUI_Hide)
$hButton = GUICtrlCreateButton("Read", 60, 360, 80, 30)
$hUP = GUICtrlCreateDummy()
$hDOWN = GUICtrlCreateDummy()
$hENTER = GUICtrlCreateDummy()
GUISetState(@SW_SHOW, $hGUI)
Dim $AccelKeys[3][2]=[["{UP}", $hUP], ["{DOWN}", $hDOWN], ["{ENTER}", $hENTER]]
GUISetAccelerators($AccelKeys)
$sCurr_Input = ""
$iCurrIndex = -1
GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")





While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $hList
            $sChosen = GUICtrlRead($hList)
            If $sChosen <> "" Then 
            GUICtrlSetData($hInput, $sChosen)
            GUICtrlSetState($hList, $GUI_Hide)
            endif
        Case $hButton
            If $sPartialData <> "" Then
                $sFinal = GUICtrlRead($hInput)
                If _ArraySearch($MyVal, $sFinal) > 0 Then
                    MsgBox(0, "Chosen", $sFinal)
                EndIf
            EndIf
        Case $hUP
            If $sPartialData <> "" Then
                $iCurrIndex -= 1
                If $iCurrIndex < 0 Then $iCurrIndex = 0
                _GUICtrlListBox_SetCurSel($hList, $iCurrIndex)
            EndIf
        Case $hDOWN
            If $sPartialData <> "" Then
                $iTotal = _GUICtrlListBox_GetCount($hList)
                $iCurrIndex += 1
                If $iCurrIndex > $iTotal - 1 Then $iCurrIndex = $iTotal - 1
                _GUICtrlListBox_SetCurSel($hList, $iCurrIndex)
            EndIf
        Case $hENTER
            If $iCurrIndex <> -1 Then
                $sText = _GUICtrlListBox_GetText($hList, $iCurrIndex)
                GUICtrlSetData($hInput, $sText)
                GUICtrlSetState($hList, $GUI_Hide)
                $iCurrIndex = -1
                _GUICtrlListBox_SetCurSel($hList, $iCurrIndex)
            EndIf
    EndSwitch
    If GUICtrlRead($hInput) <> $sCurr_Input Then
        CheckInputText()
        $sCurr_Input = GUICtrlRead($hInput)
    EndIf
WEnd

Func CheckInputText()
    $sPartialData = "|"
    Local $sInput = GUICtrlRead($hInput)
    If $sInput <> "" Then
        For $i = 0 To Ubound($MyVal) - 1
        
            If StringInStr($MyVal[$i], $sInput) <> 0 Then $sPartialData &= $MyVal[$i] & "|"
        Next
        GUICtrlSetData($hList, $sPartialData)
    EndIf
EndFunc   ;==>CheckInputText

Func WM_COMMAND($hWnd, $msg, $wParam, $lParam)
    $nNotifyCode = BitShift($wParam, 16)
    $nID = BitAND($wParam, 0x0000FFFF)
    If $nID = $hInput Then
        $hCtrl = $lParam
        If $nNotifyCode = $EN_CHANGE Then
            $txt = GUICtrlRead($hInput)
            For $n = 1 To UBound($MyVal) - 1
            ;Msgbox(0,"Records found: " & $n, $MyVal[$n])
                If StringCompare(StringLeft($MyVal[$n], StringLen($txt)), $txt) = 0 Then
                    GUICtrlSetData($hList, $MyVal[$n])
                    
                    if GUICtrlRead($hInput) then
                    GUICtrlSetState($hList, $GUI_show)
                    else
                    GUICtrlSetState($hList, $GUI_Hide)
                    endif
                    
                    ExitLoop
                EndIf
            Next
            
        EndIf
    EndIf
    Return $GUI_RUNDEFMSG
EndFunc  ;==>WM_COMMAND

Func SQLQuery()
$conn.Open($DSN)
$rs = ObjCreate( "ADODB.RecordSet" )
$rs.Open( "@@ PUT QUERY HERE @@", $conn )
If $RS.RecordCount Then
 While Not $RS.EOF
    $output = $output & StringStripWS($RS.Fields("@@ PUT TABLE HERE @@").Value,8) & "|" ; value of 4 columns on this line
    $RS.MoveNext
 WEnd
EndIf
global $MyVal = StringSplit($output,"|")
$conn.close
$sData = $output
    GUICtrlSetData($hList, $sData)
    $iCurrIndex = -1
    _GUICtrlListBox_SetCurSel($hList, $iCurrIndex)
EndFunc

Thank you everyone of the help! And if anyone is dealing with SQL issues and searches, go ahead and use this.  :sorcerer:

Dont forget to put the query and table at the bottom replacing the @@ signs ;)

  • Like 1

C0d3 is P0etry( ͡° ͜ʖ ͡°)

Share this post


Link to post
Share on other sites
dmob

Great stuff, works well.

Share this post


Link to post
Share on other sites
ferradavi

Hi everybody.

How to transform the following static list

$hList = GUICtrlCreateList("", 5, 30, 190, 325, BitOR(0x00100000, 0x00200000))

in a "popup menu" in Melba23's script ?

Thanks

Share this post


Link to post
Share on other sites
gcue
On 1/14/2014 at 7:58 AM, Melba23 said:

Kovacic,

 

Does this help at all? :huh:

 

#include <GUIConstantsEx.au3>
#include <Array.au3>
#Include <GuiListBox.au3>

Global $hGUI, $hInput, $hList, $sPartialData, $asKeyWords[100]

; Create list full of random 5 character "words"
Keywords()

$hGUI = GUICreate("Example", 200, 400)
$hInput = GUICtrlCreateInput("", 5, 5, 190, 20)
$hList = GUICtrlCreateList("", 5, 30, 190, 325, BitOR(0x00100000, 0x00200000))
$hButton = GUICtrlCreateButton("Read", 60, 360, 80, 30)
$hUP = GUICtrlCreateDummy()
$hDOWN = GUICtrlCreateDummy()
$hENTER = GUICtrlCreateDummy()
GUISetState(@SW_SHOW, $hGUI)

; Set accelerators for Cursor up/down and Enter
Dim $AccelKeys[3][2]=[["{UP}", $hUP], ["{DOWN}", $hDOWN], ["{ENTER}", $hENTER]]
GUISetAccelerators($AccelKeys)

$sCurr_Input = ""
$iCurrIndex = -1

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $hList
            $sChosen = GUICtrlRead($hList)
            If $sChosen <> "" Then GUICtrlSetData($hInput, $sChosen)
        Case $hButton
            If $sPartialData <> "" Then
                $sFinal = GUICtrlRead($hInput)
                If _ArraySearch($asKeyWords, $sFinal) > 0 Then
                    MsgBox(0, "Chosen", $sFinal)
                EndIf
            EndIf
        Case $hUP
            If $sPartialData <> "" Then
                $iCurrIndex -= 1
                If $iCurrIndex < 0 Then $iCurrIndex = 0
                _GUICtrlListBox_SetCurSel($hList, $iCurrIndex)
            EndIf
        Case $hDOWN
            If $sPartialData <> "" Then
                $iTotal = _GUICtrlListBox_GetCount($hList)
                $iCurrIndex += 1
                If $iCurrIndex > $iTotal - 1 Then $iCurrIndex = $iTotal - 1
                _GUICtrlListBox_SetCurSel($hList, $iCurrIndex)
            EndIf
        Case $hENTER
            If $iCurrIndex <> -1 Then
                $sText = _GUICtrlListBox_GetText($hList, $iCurrIndex)
                GUICtrlSetData($hInput, $sText)
                $iCurrIndex = -1
                _GUICtrlListBox_SetCurSel($hList, $iCurrIndex)
            EndIf
    EndSwitch

    ; If input has changed, refill list with matching items
    If GUICtrlRead($hInput) <> $sCurr_Input Then
        CheckInputText()
        $sCurr_Input = GUICtrlRead($hInput)
    EndIf

WEnd

Func CheckInputText()

    $sPartialData = "|" ; Start with delimiter so new data always replaces old
    Local $sInput = GUICtrlRead($hInput)
    If $sInput <> "" Then
        For $i = 0 To 99
            If StringInStr($asKeyWords[$i], $sInput) <> 0 Then $sPartialData &= $asKeyWords[$i] & "|"
        Next
        GUICtrlSetData($hList, $sPartialData)
    EndIf
EndFunc   ;==>CheckInputText

Func Keywords()

    Local $sData
    For $i = 0 To 99
        $asKeyWords[$i] = Chr(Random(65, 90, 1)) & Chr(Random(65, 90, 1)) & Chr(Random(65, 90, 1)) & Chr(Random(65, 90, 1))
        $sData &= $asKeyWords[$i] & "|"
    Next
    GUICtrlSetData($hList, $sData)
    $iCurrIndex = -1
    _GUICtrlListBox_SetCurSel($hList, $iCurrIndex)

EndFunc   ;==>Keywords

Please ask if anything is unclear. :)

 

M23

thank you Melba for this awesome script.  works great, except would it be possible to stay out of the while loop and do it instead with wm_notify?  i was also thinking of doing it in a combo box to simulate the searches in google.com

thanks again

Share this post


Link to post
Share on other sites
gcue

nvm i think i found another example

thanks anyway.. happy holidays

Share this post


Link to post
Share on other sites
Melba23

gcue,

Quote

would it be possible to stay out of the while loop and do it instead with wm_notify?

You actually need WM_COMMAND:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>
#include <Array.au3>
#Include <GuiListBox.au3>

Global $hGUI, $cInput, $cList, $sPartialData, $asKeyWords[100]

; Create list full of random 5 character "words"
Keywords()

$hGUI = GUICreate("Example", 200, 400)

$cInput = GUICtrlCreateInput("", 5, 5, 190, 20)
$cList = GUICtrlCreateList("", 5, 30, 190, 325, BitOR(0x00100000, 0x00200000))
$cButton = GUICtrlCreateButton("Read", 60, 360, 80, 30)
$cUP = GUICtrlCreateDummy()
$cDOWN = GUICtrlCreateDummy()
$cENTER = GUICtrlCreateDummy()
GUISetState(@SW_SHOW, $hGUI)

; Set accelerators for Cursor up/down and Enter
Dim $AccelKeys[3][2]=[["{UP}", $cUP], ["{DOWN}", $cDOWN], ["{ENTER}", $cENTER]]
GUISetAccelerators($AccelKeys)

$iCurrIndex = -1

GUIRegisterMsg($WM_COMMAND, "_WM_COMMAND")

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $cList
            $sChosen = GUICtrlRead($cList)
            If $sChosen <> "" Then GUICtrlSetData($cInput, $sChosen)
        Case $cButton
            If $sPartialData <> "" Then
                $sFinal = GUICtrlRead($cInput)
                If _ArraySearch($asKeyWords, $sFinal) > 0 Then
                    MsgBox(0, "Chosen", $sFinal)
                EndIf
            EndIf
        Case $cUP
            If $sPartialData <> "" Then
                $iCurrIndex -= 1
                If $iCurrIndex < 0 Then $iCurrIndex = 0
                _GUICtrlListBox_SetCurSel($cList, $iCurrIndex)
            EndIf
        Case $cDOWN
            If $sPartialData <> "" Then
                $iTotal = _GUICtrlListBox_GetCount($cList)
                $iCurrIndex += 1
                If $iCurrIndex > $iTotal - 1 Then $iCurrIndex = $iTotal - 1
                _GUICtrlListBox_SetCurSel($cList, $iCurrIndex)
            EndIf
        Case $cENTER
            If $iCurrIndex <> -1 Then
                $sText = _GUICtrlListBox_GetText($cList, $iCurrIndex)
                GUICtrlSetData($cInput, $sText)
                $iCurrIndex = -1
                _GUICtrlListBox_SetCurSel($cList, $iCurrIndex)
            EndIf
    EndSwitch

WEnd

Func CheckInputText()

    $sPartialData = "|" ; Start with delimiter so new data always replaces old
    Local $sInput = GUICtrlRead($cInput)
    If $sInput <> "" Then
        For $i = 0 To 99
            If StringInStr($asKeyWords[$i], $sInput) <> 0 Then $sPartialData &= $asKeyWords[$i] & "|"
        Next
        GUICtrlSetData($cList, $sPartialData)
    EndIf
EndFunc   ;==>CheckInputText

Func Keywords()

    Local $sData
    For $i = 0 To 99
        $asKeyWords[$i] = Chr(Random(65, 90, 1)) & Chr(Random(65, 90, 1)) & Chr(Random(65, 90, 1)) & Chr(Random(65, 90, 1))
        $sData &= $asKeyWords[$i] & "|"
    Next
    GUICtrlSetData($cList, $sData)
    $iCurrIndex = -1
    _GUICtrlListBox_SetCurSel($cList, $iCurrIndex)

EndFunc   ;==>Keywords

Func _WM_COMMAND($hWnd, $iMsg, $wParam, $lParam)

     ; If it was an update message from our input
    If _WinAPI_HiWord($wParam) = $EN_CHANGE And _WinAPI_LoWord($wParam) = $cInput Then
       CheckInputText()
    EndIf

EndFunc

And if you want to do something similar with a combo, I suggest looking at _GUICtrlComboBox_AutoComplete in the Help file.

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
gcue

right thats what i meant... wm_command :)

thank you again for your help

Share this post


Link to post
Share on other sites
BUNNY3005

instead of characters, I have to search for files. Can you tell me how to do?

Share this post


Link to post
Share on other sites
Melba23

BUNNY3005,

The principle is exactly the same - just fill the array with the filenames rather then the random letters. Give it a go and see what happens - you know where we are if you run into problems.

M23

  • Like 1

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
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

  • Similar Content

    • nooneclose
      By nooneclose
      My program has to first search for names in Column D that do not match up with column C. I got that search to work using arrays. It was slow and I could not figure out how to delete them so I just manually put coded the names that do not belong. I found their cell location but I do not know how to store that location and delete it.
      This is what I have so far.
      Local $NameToDelete1[6]  = _Excel_RangeFind($OpenWorkbook, "Smith, Bill") _ArrayDisplay($NameToDelete1, "Excel UDF: _Excel_RangeFind Example 1", "", 0, "|", "Sheet|Name|Cell|Value|Formula|Comment") _Excel_RangeDelete($OpenWorkbook.ActiveSheet, $NameToDelete1[2], $xlShiftUp)  
      Please help, I wanted to have this program done yesterday but I did not see this problem until yesterday. 
    • Lisuter
      By Lisuter
      Hello...

      How i can write data from txt to +3 Input?
      Example:
      In txt i have:
      Michael XYZ, 21, Boston
      Olex Marshal, 17, Boston
      Alex XYZ, 19, Boston
       
      And now i want load that data to input in autoit. 

      Name          y.o          city
      [ Input1]  [Input2] [Input3]
      [ Input4]  [Input5] [Input6]
      [ Input7]  [Input8] [Input9]
       
      After load should be:
      Name               y.o            city
      [Michael XYZ]      [21]     [Boston]
      [ Olex Marshal]  [17]      [Boston]
      [ Alex XYZ]           [19]      [Boston]
       
      FileOpen("Test.txt",0)                          $aas = GUICtrlSetData($Input1, FileReadLine("Test.txt",1))             FileClose("Test.txt") But its wrong. ofcourse its load all to input 1. So now how do you load this data directly into each input separately? The comma stop sign is here. Each line is a new person
    • Skeletor
      By Skeletor
      Hi All,
      While creating a few excel spreadsheets using AutoIt, I came across something which to my limiting time to research the forums I don't anyone has mentioned. 
      The color pallettes are reversed. 
      Huge shock to me.
       
      I wanted to produce a red row but kept on getting blue. 
      Seems like 0xFF0000 was red on the charts but when running the script, I got blue. 
      I then played around with the colors, and after a few tries, I finally got Red. 
      Reversed the FF0000 and the result is 0000FF.
       
      So for Excel compared to Html
      0000FF (Red) - Excel
      0000FF (Blue) - Html

      FFFF00 (Cyan) - Excel
      FFFF00(Yellow) - Html
       
    • AndyS19
      By AndyS19
      I'm trying to implement a Ctl-F popup box that looks something like the one that Notepad uses, but I'm not havine much luck.  I intend to get it working, then beef up the popup's contents to add several checkboxes, buttons and radio boxes.
      What my example code does is to use InputBox(), but that's not what I want.
      Here is my test code:
      #include <Array.au3> #include <GUIConstantsEx.au3> #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 Opt("GUICloseOnESC", 1) Opt("GUIOnEventMode", 1) Opt('MustDeclareVars', 1) OnAutoItExitRegister("ExitStageLeft") Opt("WinTitleMatchMode", -2) Global $hGUI _Main() Func _Main() $hGUI = GUICreate("Test ^F", 300, 200) setupSpecialKeysHandlers() GUISetOnEvent($GUI_EVENT_CLOSE, "Event_GUIClose") GUISetState() While (1) Sleep(157) WEnd EndFunc ;==>_Main Func handle_CTRL_F_key() Local $str $str = InputBox("Search", "Enter the string to search for:") ConsoleWrite("+++: $str ==>" & $str & "<==" & @CRLF) EndFunc ;==>handle_CTRL_F_key Func ExitStageLeft() Exit (99) EndFunc ;==>ExitStageLeft Func Event_GUIClose() Exit (1) EndFunc ;==>Event_GUIClose Func setupSpecialKeysHandlers() Local $ar, $parts, $key, $handler, $id Local $aAccelKeys[1][2] ; Create a table of Special keys and their handlers $ar = StringSplit("", "") _ArrayAdd($ar, "^f - handle_CTRL_F_key ") ReDim $aAccelKeys[UBound($ar) - 1][2] ; Now, create $aAccelKeys array with the table data. ; For each entry, create a Dummy GUI and associate its ; ID with the special key. For $ndx = 1 To UBound($ar) - 1 $parts = StringSplit($ar[$ndx], "-", 2) $key = StringStripWS($parts[0], 8) $handler = StringStripWS($parts[1], 8) $id = GUICtrlCreateDummy() $aAccelKeys[$ndx - 1][0] = $key $aAccelKeys[$ndx - 1][1] = $id GUICtrlSetOnEvent($id, $handler) Next GUISetAccelerators($aAccelKeys) ; Setup the Special keys hooks EndFunc ;==>setupSpecialKeysHandlers  
    • Atoxis
      By Atoxis
      Howdy, I've gone through a lot of au3 forums, and I once had a working Imagesearch script that I got from here.  However, and i'm just totally not sure how but my imagesearch scripts aren't working anymore.
      I'm not new to au3 but i'm not the most experienced with it's syntax/commands.

      Anyways, I've looked over the big threads involving imagesearch.

      Does anyone have a working Imagesearch x64 for win10 that is currently working as of the date with the post.

      Dll's and what not is fine, just when I tell the script to run, I want to be able to find the image on the screen!
      Can't find a working copy so if anyone has one please send it my way lol.

      I've taken all the imagesearch downloads and what not and have played with them but I can't get any of them working on my end, despite others saying they're working.
      Thanks.
×