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
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
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

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

    • lenclstr746
      By lenclstr746
      HELLO GUYS
      I'm a work on a background see and click bot project 
      I can complete it if your help me
      (using imagesearch , gdi+ and  fastfind)
    • Ascer
      By Ascer
      1. Description.
      oAuth 2.0 is security system implemented by Google a few years ago. You are able to connect into your Google accounts and manage documents. In this UDF i show you how to pass first authorization process., this allow you to automate most of functions using API interface. 2. Requirements.
      Google account. oAuth.au3 Download 3. Possibilities
      ;============================================================================================================ ; Date: 2018-02-10, 14:21 ; ; Description: UDF for authorize your app with oAuth 2.0 Google. ; ; Function(s): ; oAuth2GetAuthorizationCode() -> Get Code for "grant". ; oAuth2GetAccessToken() -> Get "access_token" and "refresh_token" first time. ; oAuth2RefreshAccessToken() -> Get current "access_token" using "refresh_token". ; ; Author(s): Ascer ;============================================================================================================ 4. Enable your Google API.
          4.1. Video Tutorial not mine!
       YouTube     4.2 Screenshots from authorization process (Polish language) 
      Go to https://console.developers.google.com/apis/dashboard and accept current rules.  

       
      Next create an new project  

       
      Enter name of you new project and click Create  

       
      Google will working now, please wait until finish. Next go to enable your API interface, we make if for Google  

       
      Take "Gmail" in search input and after click in found result.  

       
      Click Enable interface, Google will working now.  

       
      Create your login credentials  

       
      Select Windows Interface (combobox), User credentials (radio) and click button what is need bla bla  

       
      Type name of a new client id for oAuth 2.0 and click Create a new Client ID.  

       
      Next configure screen aplication, type some name and click Next. Google will working now.  

       
      Last step on this website is download source with your credentials in *Json format.  

       
      Now you received a file named client_id.json, it's how it look in Sublime Text:  

       
      5. Coding.
      Now we need to call a some function to get access code.  
      #include <oAuth.au3> Local $sClientId = "167204758184-vpeues0uk6b0g4jrnv0ipq5fapoig2v8.apps.googleusercontent.com" Local $sRedirectUri = "http://localhost" oAuth2GetAuthorizationCode($sClientId, $sRedirectUri)  
      Function will execute default browser for ask you to permission.  

       
      Next Google ask you to permission for access to your personal details by application Autoit   

       
      Now you can thing is something wrong but all is ok, you need to copy all after  code= . It your access code.  

       
      Let's now ask Google about our Access Token and Refresh Token  
      #include <oAuth.au3> Local $sClientId = "167204758184-vpeues0uk6b0g4jrnv0ipq5fapoig2v8.apps.googleusercontent.com" Local $sClientSecret = "cWalvFr3WxiE6cjUkdmKEPo8" Local $sAuthorizationCode = "4/AAAPXJOZ-Tz0s6mrx7JbV6nthXSfcxaszFh_aH0azVqHkSHkfiwE8uamcabn4eMbEWg1eAuUw7AU0PQ0XeWUFRo#" Local $sRedirectUri = "http://localhost" Local $aRet = oAuth2GetAccessToken($sClientId, $sClientSecret, $sAuthorizationCode, $sRedirectUri) If Ubound($aRet) <> 4 then ConsoleWrite("+++ Something wrong with reading ResponseText." & @CRLF) Exit EndIf ConsoleWrite("Successfully received data from Google." & @CRLF) ConsoleWrite("access_token: " & $aRet[0] & @CRLF) ConsoleWrite("expires_in: " & $aRet[1] & @CRLF) ConsoleWrite("refresh_token: " & $aRet[2] & @CRLF) ConsoleWrite("token_type: " & $aRet[3] & @CRLF)  
      Important! When you received error 400 and output says: Invalid grant it means that your previous generated access_code lost validity and you need to generate new calling previus code. When everything is fine you should received a 4 informations about your: access_token, expires_in, refresh_token and token_type. Access_Token time is a little short so you need to know fuction possible to refresh it (tell Google that he should generate a new Token for you)  
      #include <oAuth.au3> Local $sRefreshToken = "1/ba8JpW7TjQH3-UI1BvPaXhSf-oTQ4BmZAbBfhcKgKfY" Local $sClientId = "167204758184-vpeues0uk6b0g4jrnv0ipq5fapoig2v8.apps.googleusercontent.com" Local $sClientSecret = "cWalvFr3WxiE6cjUkdmKEPo8" Local $sRedirectUri = "http://localhost" Local $aRet = oAuth2RefreshAccessToken($sRefreshToken, $sClientId, $sClientSecret) If Ubound($aRet) <> 3 then ConsoleWrite("+++ Something wrong with reading ResponseText." & @CRLF) Exit EndIf ConsoleWrite("Successfully received data from Google." & @CRLF) ConsoleWrite("access_token: " & $aRet[0] & @CRLF) ConsoleWrite("expires_in: " & $aRet[1] & @CRLF) ConsoleWrite("token_type: " & $aRet[2] & @CRLF)  
      6. Finish words
      If you followed all this above steps im sure that you received all informations required for coding your Google API (Gmail, Dropbox, YouTube, Calender etc. See next thread: [UDF] Gmail API - Email automation with AutoIt!
    • dadalt95
      By dadalt95
      Perform a simple google search!
      The script below works fine until fill the google form!
      What I can't find is how to submit the form, tried a couple of ways and none of them worked.

       
      #include <IE.au3> $oIE = _IECreate ("www.google.com") $o_form = _IEFormGetObjByName ($oIE, "f") $o_login = _IEFormElementGetObjByName ($o_form, "q") $username = "80251369" _IEFormElementSetValue ($o_login, $username) $o_numer = _IEGetObjByName($o_form, "btnK") _IEAction ($o_numer, "click")  
      The code runs without any problem.
      I don't know how to proceed!
      Thanks in advance!
    • nacerbaaziz
      By nacerbaaziz
      Hi dears
      how are you? I hope You fine
      I have a question please
      I've created a listView
      It has several columns
      Is there any way  to search for text in an element of this list with text in all columns
      for example
      list view with 2 column
      the first is the file name and the second is the file path
      and i want to search for the item witch Containt the name and the path toGether
      I searched a lot but could not find what I was looking for
      If you do not understand the idea that I'm looking for, I can put an example
      Thanks in advance
×