Jump to content

prompt in inputbox


Recommended Posts

Hi I wish to create an input box like the image attached:

When I type something, it should give a prompt as shown, giving possible options from which user can select without the need to type the whole thing.

Can this be done in a GUI?

If yes, please can you point me in the right direction..

Thanks and Regards,

M

[font="Garamond"]Manjish Naik[/font]Engineer, Global Services - QPSHoneywell Automation India LimitedE-mail - Manjish.Naik@honeywell.com
Link to comment
Share on other sites

Hi I wish to create an input box like the image attached:

When I type something, it should give a prompt as shown, giving possible options from which user can select without the need to type the whole thing.

Can this be done in a GUI?

If yes, please can you point me in the right direction..

Thanks and Regards,

M

the first idea that came into my head:

the first line is an input control (that's obvious)

below it it is an read-only edit control, label... up to you

you will fill that edit control with the words to autocomplete

and you loop

while 1
 $s=GuiCtrlRead($input)
 _ShowWordsStartingWith($s)
wend

and check if the down keystroke has been pressed

good luck!

I ran. I ran until my muscles burned and my veins pumped battery acid. Then I ran some more.

Link to comment
Share on other sites

  • Moderators

Manjish,

This not quite what you wanted, but using it might save you a lot of coding >_< :

#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiComboBox.au3>

Dim $sString = "Hello|world|AutoIt|rules|and|more|some|data"

$hGUI = GUICreate("Search in combo demo", 300, 200)

$hCombo = GUICtrlCreateCombo("", 70, 75, 170, 20)
GUICtrlSetData(-1, $sString, "Hello")

GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")

GUISetState()

Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE

Func WM_COMMAND($hWnd, $Msg, $wParam, $lParam)
    Local $iIDFrom = BitAND($wParam, 0x0000FFFF)
    Local $iCode = BitShift($wParam, 16)
    
    Switch $iIDFrom
        Case $hCombo
            Switch $iCode
                Case $CBN_EDITCHANGE
                    _GUICtrlComboBox_AutoComplete($hCombo)
            EndSwitch
    EndSwitch
    
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_COMMAND

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
Share on other sites

Just an example, you can make it better. I use only one letter instead words but is the same thing.

Global $INPUT, $LIST
$MAIN = GUICreate("Example",200,400)
$INPUT = GUICtrlCreateInput("",5,5,190,20)
$LIST = GUICtrlCreateList("",5,30,190,365,BitOR(0x00100000,0x00200000))
Keywords()
GUISetState(@SW_SHOW,$MAIN)

AdlibEnable("CheckInputText",100)

While True
    $MSG = GUIGetMsg()
    If $MSG = -3 Then 
        AdlibDisable()
        Exit
    EndIf
    Sleep(15)
WEnd

Func Keywords()
    Global $LIST_DATA = ""
    Global $KEYWORD[100]
    For $INDEX = 0 To 99
        $KEYWORD[$INDEX] = Chr(Random(65,90,1))
        $LIST_DATA &= $KEYWORD[$INDEX] & "|"
    Next
    GUICtrlSetData($LIST,$LIST_DATA)
EndFunc

Func CheckInputText()
    Local $NEW_DATA = ""
    $READ = GUICtrlRead($INPUT)
    If $READ <> "" Then
        For $INDEX = 0 To 99
            If StringLeft($KEYWORD[$INDEX],1) = $READ Then $NEW_DATA &= $KEYWORD[$INDEX] & "|"
        Next
        GUICtrlSetData($LIST,"")
        GUICtrlSetData($LIST,$NEW_DATA)
    EndIf
EndFunc
Edited by Andreik

When the words fail... music speaks.

Link to comment
Share on other sites

Hi, if I didn't make my intentions clear in the first post, here's what I wanna do:

I have a list of possible options which I wanna show to the user..

suppose: apple, america, adder, adamant is in the list

when user types "a".. he gets these 4..

when he types "ad".. he only gets adamant and adder..

when he types "ada" he only gets adamant..

and so on...

@M23..

Hey thanks for the suggestion.. But unfortunately I can't use this.. as I will add atleast 100-150 entries in the prompts list.. So if I add 150 entries in combobox..and if the user clicks the browse button (which he's bound to do on a combobox), it will be havoc.. A huge list.. half of it going beyond the bounds.. But thanks anyways, as u said, it will save me some code

@Andreik..

I think this is what I was looking for.. I got an idea looking at this.. I will create an array of the prompts (data fed into array using a filereadline, from the file, listing all the prompts).. then I will do a stringinstr + array search.. and then dump all those items into the list.. Will have to check this.. Do u guys think its feasible?

[font="Garamond"]Manjish Naik[/font]Engineer, Global Services - QPSHoneywell Automation India LimitedE-mail - Manjish.Naik@honeywell.com
Link to comment
Share on other sites

Ok guys.. Here's what I have.. It's working just the way I want it to.. Using Anreik's idea as the basis of it..

But now I am facing a new issue.. Suppose user finds, what he needs in the prompt list.. Now when he clicks that prompt, The value in the inputbox should be changed to that... How do I go about that.. Also I need to initially hide the list box and later when input entry is given, the list should be shown.. Some help??

Global $INPUT, $LIST
$MAIN = GUICreate("Example",200,400)
$INPUT = GUICtrlCreateInput("",5,5,190,20)
$LIST = GUICtrlCreateList("",5,30,190,365,BitOR(0x00100000,0x00200000))
$file = FileOpen("list.txt", 0)

; Check if file opened for reading OK
If $file = -1 Then
    MsgBox(0, "Error", "Unable to open file.")
    Exit
EndIf

Keywords()
GUISetState(@SW_SHOW,$MAIN)

AdlibEnable("CheckInputText",100)

While True
    $MSG = GUIGetMsg()
    If $MSG = -3 Then 
        AdlibDisable()
        Exit
    EndIf
    Sleep(15)
WEnd

Func Keywords()
    Global $LIST_DATA = ""
    Global $KEYWORD[100]
    For $INDEX = 0 To 99
        $KEYWORD[$INDEX] = FileReadLine($file)
        if $KEYWORD[$INDEX]="" Then ExitLoop
        ;MsgBox(4096,"",$KEYWORD[$INDEX])
        $LIST_DATA &= $KEYWORD[$INDEX] & "|"
    Next
    GUICtrlSetData($LIST,$LIST_DATA)
EndFunc

Func CheckInputText()
    $l=StringLen(guictrlread($input))
    Local $NEW_DATA = ""
    $READ = GUICtrlRead($INPUT)
    If $READ <> "" Then
        For $INDEX = 0 To 99
            If StringLeft($KEYWORD[$INDEX],$l) = $READ Then $NEW_DATA &= $KEYWORD[$INDEX] & "|"
        Next
        GUICtrlSetData($LIST,"")
        GUICtrlSetData($LIST,$NEW_DATA)
    EndIf
EndFunc

Edited by Manjish
[font="Garamond"]Manjish Naik[/font]Engineer, Global Services - QPSHoneywell Automation India LimitedE-mail - Manjish.Naik@honeywell.com
Link to comment
Share on other sites

  • Moderators

Manjish,

Lucky you - it is raining hard and I am stuck indoors. I have made the data list random as I do not have your file - other changes are marked.

#include <GUIConstantsEx.au3>   ; <<<<<<<<<<<<<<<<<<<<<<<<<< added

Global $INPUT, $LIST
Global $LIST_DATA = "", $KEYWORD[100] ; <<<<<<<<<<<<<<<<<<< Not good to declare Global in function so moved here

$MAIN = GUICreate("Example",200,400)
$INPUT = GUICtrlCreateInput("",5,5,190,20)
$LIST = GUICtrlCreateList("",5,30,190,365,BitOR(0x00100000,0x00200000))
GUICtrlSetState(-1, $GUI_HIDE) ; <<<<<<<<<<<<<<<<<<<<<<<<< hide the list initially


Keywords()
GUISetState(@SW_SHOW,$MAIN)

AdlibEnable("CheckInputText",100)

While True
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            AdlibDisable()
            Exit
        Case $LIST ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<< if list is clicked read the chosen item and put in the input
            $sChosen = GUICtrlRead($LIST)
            GUICtrlSetData($INPUT, $sChosen)

    EndSwitch
    ; Sleep(15)    ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Not needed with a GUIGetMsg call in the loop

    ; <<<<<<<<<<<<<<<<<<<<<<<<<< If the input is not empty and the list is hidden - show the list
    If GUICtrlRead($INPUT) <> "" And BitAND(GUICtrlGetState($LIST), $GUI_HIDE) = $GUI_HIDE Then GUICtrlSetState($LIST, $GUI_SHOW)

WEnd

Func Keywords()

    For $INDEX = 0 To 99
        $KEYWORD[$INDEX] = Chr(Random(65,90,1)) & Chr(Random(65,90,1)) & Chr(Random(65,90,1)) & Chr(Random(65,90,1)) & Chr(Random(65,90,1))
        if $KEYWORD[$INDEX]="" Then ExitLoop
        ;MsgBox(4096,"",$KEYWORD[$INDEX])
        $LIST_DATA &= $KEYWORD[$INDEX] & "|"
    Next
    GUICtrlSetData($LIST,$LIST_DATA)
EndFunc

Func CheckInputText()
    $l=StringLen(guictrlread($input))
    Local $NEW_DATA = ""
    $READ = GUICtrlRead($INPUT)
    If $READ <> "" Then
        For $INDEX = 0 To 99
            If StringLeft($KEYWORD[$INDEX],$l) = $READ Then $NEW_DATA &= $KEYWORD[$INDEX] & "|"
        Next
        GUICtrlSetData($LIST,"")
        GUICtrlSetData($LIST,$NEW_DATA)
    EndIf
EndFunc

Anything else? >_<

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
Share on other sites

You can play around with this script.

Input letters in the top input box.

click left mouse button to highlight a selected line in Rich edit box.

Right click in Edit box to select highlighted line.

Right click once or twice in edit box to clear input box, or use backspace in input box.

At about line #42, the data used is specified in variable, $sText. By swapping the comment tag, (;), you could use the Mozilla Firefox dictionary, if you have it installed.

Esc to exit.

;
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>
#include <GuiEdit.au3>

; Scroll - http://www.autoitscript.com/forum/index.php?showtopic=46790&view=findpost&p=350587
; GuiRichEdit.au3 - http://www.autoitscript.com/forum/index.php?showtopic=21522&view=findpost&p=148943

Opt("MouseCoordMode", 2) ;1=absolute, 0=relative, 2=client
Opt('MustDeclareVars', 1)

HotKeySet("{ESC}", "Quit") ;Alt-r

Global $oMyError, $oRP
Global Const $EM_SHOWSCROLLBAR = ($WM_USER + 96)
Global Const $EM_SETWORDWRAPMODE = ($WM_USER + 102)
Global Const $SB_HORZ = 0
Global Const $SB_VERT = 1
Global Const $SB_BOTH = 3
Global $idInput, $sInputDat, $rt_handle, $sText, $sOldInput
RichEditExample()

; Modified Rich edit control EXAMPLE using GUICtrlCreateObj
Func RichEditExample()
    Local $TagsPageC, $AboutC, $PrefsC, $StatC, $GUIActiveX, $begin, $msg, $hGUI, $aPartRightSide[2] = [378, -1]
    Local $StatusBar, $MaxDisp, $aMaxln, $start, $sLinesInfo = "", $sTitle = "Embedded RICHTEXT control Test"
    $oMyError = ObjEvent("AutoIt.Error", "MyErrFunc")

    $oRP = ObjCreate("RICHTEXT.RichtextCtrl.1")

    $hGUI = GUICreate($sTitle, 190, 200, -1, -1, BitOR($WS_CLIPSIBLINGS, $WS_POPUP, $WS_POPUPWINDOW, $WS_CLIPCHILDREN))
    $idInput = GUICtrlCreateInput("", 0, 0, 190, 20)
    GUICtrlSetBkColor($idInput, 0xFFFFEF)
    GUIRegisterMsg(0x0111, "_Input")

    $GUIActiveX = GUICtrlCreateObj($oRP, 10, 30, 190, 180)
    GUICtrlSetPos($GUIActiveX, 0, 20, 190, 180)
    GUICtrlSetResizing($GUIActiveX, (2 + 4 + 32 + 64))

    ;$sText = StringRegExpReplace(FileRead("C:\Program Files\Mozilla Firefox\dictionaries\en-US.dic"), "(.+?)(/*[a-zA-Z0-9]*)(\v+|$|\z)","\1\3")
    $sText = FileRead("list.txt")

    With $oRP; Object
        .OLEDrag()
        .Enabled = True
        .Font = 'Arial'
        .text = $sText
        .BackColor = 0xEFFFFF
    EndWith
    $rt_handle = $oRP.Hwnd
    Local $ww = $oRP.Multiline
    ;$rt_handle = ControlGetHandle("Embedded RICHTEXT control Test", "", "RichTextWndClass1")
    _SendMessage($rt_handle, $EM_SETWORDWRAPMODE, 0, 0)

    _SendMessage($rt_handle, $EM_SHOWSCROLLBAR, $SB_VERT, True)

    Local $aCPos = ControlGetPos($sTitle, "", "RichTextWndClass1")
    ControlClick($sTitle, "", "RichTextWndClass1", "left", 1, $aCPos[0] + 10, $aCPos[1] + $aCPos[3] - 18)

    ControlSend($sTitle, "", "RichTextWndClass1", "^{END}")
    Sleep(10)
    ControlSend($sTitle, "", "RichTextWndClass1", "^{HOME}")

    GUISetState();Show GUI
    ControlFocus($sTitle, "", $idInput)
    While 1
        $msg = GUIGetMsg()
        Switch $msg
            Case $GUI_EVENT_CLOSE
                $oRP.SaveFile(@ScriptDir & "\RichText.rtf", 0)
                ExitLoop
            Case $GUI_EVENT_SECONDARYUP
                Local $sSelText = $oRP.SelText
                GUICtrlSetData($idInput, $sSelText)
                ClipPut($sSelText)
                ControlFocus($sTitle, "", $idInput)
            Case $GUI_EVENT_PRIMARYUP
                Local $start = _Char0LinePos($oRP)
                $oRP.SelStart = $start
                $oRP.SelLength = _SendMessage($rt_handle, $EM_LINELENGTH, $start)
        EndSwitch
    WEnd
    GUIDelete()
EndFunc   ;==>RichEditExample

Func _Input($hWnd, $msg)
    Local $iSpacing, $sNewText, $aLineNum, $iNumLines, $iLineLength
    $sInputDat = GUICtrlRead($idInput)
    If $sOldInput <> $sInputDat Then
        GUICtrlSetData($idInput, $sInputDat)
        If $sInputDat = "" Then
            $iSpacing = Int(_GUICtrlRichEditGetLineCount($rt_handle) / 50) + 1
            $sNewText = StringRegExpReplace($sText, "(?i)(?m)((.*)(\v+|$|\z)){" & $iSpacing & "}|^(?:.*(\v+|$|\z))", "\2\3")
        Else
            $sNewText = StringRegExpReplace($sText, "(?i)(?m)(" & $sInputDat & ".*(\v+|$|\z))|^(?:.*(\v+|$|\z))", "\1")
        EndIf
        $aLineNum = StringRegExp($sNewText, ".+(?=\v+|$)", 3) ; returns array of every line
        $iNumLines = UBound($aLineNum)
        While $iNumLines > 100
            $iSpacing = Int($iNumLines / 50) + 1
            $sNewText = StringRegExpReplace($sNewText, "(?i)(?m)((.*)(\v+|$|\z)){" & $iSpacing & "}|^(?:.*(\v+|$|\z))", "\2\3");
            $aLineNum = StringRegExp($sNewText, ".+(?=\v+|$)", 3) ; returns array of every line
            $iNumLines = UBound($aLineNum)
        WEnd
        $oRP.text = $sNewText
        For $x = 0 To _GUICtrlRichEditGetLineCount($rt_handle) - 2
            Local $start = _SendMessage($rt_handle, $EM_LINEINDEX, $x)
            $oRP.SelStart = $start
            $oRP.SelLength = StringLen($sInputDat)
            $oRP.SelColor = 0x0000FF
            $iLineLength = _SendMessage($rt_handle, $EM_LINELENGTH, $start)
            $start += StringLen($sInputDat)
            $oRP.SelStart = $start
            $oRP.SelLength = ($iLineLength - StringLen($sInputDat))
            $oRP.SelColor = 0x000000
        Next

        $sOldInput = $sInputDat
    EndIf
    Return $GUI_RUNDEFMSG
EndFunc   ;==>_Input

Func _GUICtrlRichEditGetLineCount($h_RichEdit)
    If Not IsHWnd($h_RichEdit) Then $h_RichEdit = HWnd($h_RichEdit)
    Return _SendMessage($h_RichEdit, $EM_GETLINECOUNT)
EndFunc   ;==>_GUICtrlRichEditGetLineCount

;Returns numbers characters from beginning of text to te first character of the line the caret is in at time of calling.
Func _Char0LinePos($oRP)
    Local $ChkLine, $iCol, $iStartOfLine, $iCharPos, $iLineNum
    $iCharPos = $oRP.SelStart
    $iStartOfLine = $iCharPos
    $iLineNum = $oRP.GetLineFromChar($iCharPos)
    If $iLineNum = 0 Then
        $iStartOfLine = -1
    Else
        While 1
            $iStartOfLine -= 1
            $ChkLine = $oRP.GetLineFromChar($iStartOfLine)
            If $ChkLine <> $iLineNum Then ExitLoop 1
        WEnd
    EndIf
    Return $iStartOfLine + 1
EndFunc   ;==>_Char0LinePos

Func Quit()
    Exit
EndFunc   ;==>Quit

Func MyErrFunc()
    MsgBox(0, "AutoItCOM Test", "We intercepted a COM Error !" & @CRLF & @CRLF & _
            "err.description is: " & @TAB & $oMyError.description & @CRLF & _
            "err.windescription:" & @TAB & $oMyError.windescription & @CRLF & _
            "err.number is: " & @TAB & Hex($oMyError.number, 8) & @CRLF & _
            "err.lastdllerror is: " & @TAB & $oMyError.lastdllerror & @CRLF & _
            "err.scriptline is: " & @TAB & $oMyError.scriptline & @CRLF & _
            "err.source is: " & @TAB & $oMyError.source & @CRLF & _
            "err.helpfile is: " & @TAB & $oMyError.helpfile & @CRLF & _
            "err.helpcontext is: " & @TAB & $oMyError.helpcontext _
            , 5)
    ; Will automatically continue after 5 seconds
    ConsoleWrite($oMyError.helpfile & @CRLF)
    Local $err = $oMyError.number
    If $err = 0 Then $err = -1
    SetError($err) ; to check for after this function returns
EndFunc   ;==>MyErrFunc
;
Link to comment
Share on other sites

@M23,

Thanks M.. but there are some problems tho..

1) When i click the list first time, the guictrlread() gives a blank result. It give the clicked option only when list is clicked twice. You can use the list.txt file attached in my previous post.

2) Also there's one more problem. I don't want to set the height of the listview more than 80. So automatically it gets a scroll bar if the entries don't fit into the height. Now, as we have put the guictrlsetdata() in the adlib function, the list gets populated with the data again and again. Hence if u try to scroll down, u automatically get scrolled up, as the data is repopulated.

3) Also, if type a letter like "z" and if there are no words starting with this letter, then ideally I shouldn't get a list. But instead I get a blank list.

#include <GUIConstantsEx.au3>   ; <<<<<<<<<<<<<<<<<<<<<<<<<< added

Global $INPUT, $LIST
Global $LIST_DATA = "", $KEYWORD[100] ; <<<<<<<<<<<<<<<<<<< Not good to declare Global in function so moved here

$MAIN = GUICreate("Example",200,400)
$INPUT = GUICtrlCreateInput("",5,5,190,20)
$LIST = GUICtrlCreateList("",5,25,190,80,BitOR(0x00100000,0x00200000))
$file=FileOpen("list.txt",0)
GUICtrlSetState(-1, $GUI_HIDE) ; <<<<<<<<<<<<<<<<<<<<<<<<< hide the list initially


Keywords()
GUISetState(@SW_SHOW,$MAIN)

AdlibEnable("CheckInputText",100)

While True
    ;MsgBox(4096,"",)
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            AdlibDisable()
            Exit
        Case $LIST ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<< if list is clicked read the chosen item and put in the input
            
            $sChosen = GUICtrlRead($LIST)
            MsgBox(4096,"",$schosen)
            GUICtrlSetData($INPUT, $sChosen)
            GUICtrlSetState($list,$gui_hide)

    EndSwitch
    ; Sleep(15)    ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Not needed with a GUIGetMsg call in the loop

    ; <<<<<<<<<<<<<<<<<<<<<<<<<< If the input is not empty and the list is hidden - show the list
    If GUICtrlRead($INPUT) <> "" And BitAND(GUICtrlGetState($LIST), $GUI_HIDE) = $GUI_HIDE Then GUICtrlSetState($LIST, $GUI_SHOW)

WEnd

Func Keywords()
    Global $keyword[100]
    For $INDEX = 0 To 99
        $KEYWORD[$INDEX] = FileReadLine($file)
        if $KEYWORD[$INDEX]="" Then ExitLoop
        $LIST_DATA &= $KEYWORD[$INDEX] & "|"
    Next
    GUICtrlSetData($LIST,$LIST_DATA)
EndFunc

Func CheckInputText()
    $l=StringLen(guictrlread($input))
    Local $NEW_DATA = ""
    $READ = GUICtrlRead($INPUT)
    If $READ <> "" Then
        For $INDEX = 0 To 99
            If StringLeft($KEYWORD[$INDEX],$l) = $READ Then $NEW_DATA &= $KEYWORD[$INDEX] & "|"
        Next
        GUICtrlSetData($LIST,"")
        GUICtrlSetData($LIST,$NEW_DATA)
    EndIf
EndFunc
Edited by Manjish
[font="Garamond"]Manjish Naik[/font]Engineer, Global Services - QPSHoneywell Automation India LimitedE-mail - Manjish.Naik@honeywell.com
Link to comment
Share on other sites

Ok I dealt with problem no. 3..

Still not able to solve 1 and 2.. Anbody out there has a solution? pls help

#include <GUIConstantsEx.au3>   ; <<<<<<<<<<<<<<<<<<<<<<<<<< added
#include <GuiListBox.au3>
Global $INPUT, $LIST
Global $LIST_DATA = "", $KEYWORD[100] ; <<<<<<<<<<<<<<<<<<< Not good to declare Global in function so moved here
$file=FileOpen("list.txt",0)
$MAIN = GUICreate("Example",200,400)
$INPUT = GUICtrlCreateInput("",5,5,190,20)
$LIST = GUICtrlCreateList("",5,25,190,80,BitOR(0x00100000,0x00200000))
GUICtrlSetState(-1, $GUI_HIDE) ; <<<<<<<<<<<<<<<<<<<<<<<<< hide the list initially


Keywords()
GUISetState(@SW_SHOW,$MAIN)

AdlibEnable("CheckInputText",500)

While True
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            AdlibDisable()
            Exit
        Case $LIST ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<< if list is clicked read the chosen item and put in the input
            $sChosen = GUICtrlRead($LIST)
            GUICtrlSetData($INPUT, $sChosen)
            GUICtrlSetState($LIST, $GUI_HIDE)
    EndSwitch
     ;Sleep(15)    ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Not needed with a GUIGetMsg call in the loop

    ; <<<<<<<<<<<<<<<<<<<<<<<<<< If the input is not empty and the list is hidden - show the list
    If GUICtrlRead($INPUT) <> "" Then
        ;sleep(200)
        If BitAND(GUICtrlGetState($LIST), $GUI_HIDE) = $GUI_HIDE And _guictrllistbox_getcount($LIST)<>0 Then GUICtrlSetState($LIST, $GUI_SHOW)
        ElseIf GUICtrlRead($INPUT) = "" And BitAND(GUICtrlGetState($LIST), $GUI_show) = $GUI_show And _guictrllistbox_getcount($LIST)=0 Then 
            GUICtrlSetState($LIST, $GUI_hide)   
    EndIf
;MsgBox(4096,"",_guictrllistbox_getcount($LIST))
WEnd

Func Keywords()
    Global $keyword[100]
    For $INDEX = 0 To 99
        $KEYWORD[$INDEX] = FileReadLine($file)
        if $KEYWORD[$INDEX]="" Then ExitLoop
        $LIST_DATA &= $KEYWORD[$INDEX] & "|"
    Next
EndFunc

Func CheckInputText()

    $l=StringLen(guictrlread($input))
    Local $NEW_DATA = ""
    $READ = GUICtrlRead($INPUT)
    if $read="" Then  GUICtrlSetData($LIST,"")
    If $READ <> "" Then
        For $INDEX = 0 To 99
            If StringLeft($KEYWORD[$INDEX],$l) = $READ Then $NEW_DATA &= $KEYWORD[$INDEX] & "|"
        Next
        GUICtrlSetData($LIST,"")
        GUICtrlSetData($LIST,$NEW_DATA)
    EndIf
EndFunc
[font="Garamond"]Manjish Naik[/font]Engineer, Global Services - QPSHoneywell Automation India LimitedE-mail - Manjish.Naik@honeywell.com
Link to comment
Share on other sites

  • Moderators

Manjish,

All the problems were being caused by the Adlib, so I have rejigged the code to remove it.

Your problems:

1. Clicking the list now fills the input.

2. The list is no longer autorefilled every 100 msecs, so no scrolling to the top every 100 msecs.

3. No entries = no list (I know you said you had fixed it, but I did it my way!)

#include <GUIConstantsEx.au3>

Global $INPUT, $LIST, $LIST_DATA = "", $KEYWORD[100], $NEW_DATA = "|"

$MAIN = GUICreate("Example",200,400)
$INPUT = GUICtrlCreateInput("",5,5,190,20)
$LIST = GUICtrlCreateList("",5,30,190,365,BitOR(0x00100000,0x00200000))
GUICtrlSetState(-1, $GUI_HIDE)

Keywords()
GUISetState(@SW_SHOW,$MAIN)

$sCurr_Input = ""

While True
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $LIST
            $sChosen = GUICtrlRead($LIST)
            If $sChosen <> "" Then GUICtrlSetData($INPUT, $sChosen)
    EndSwitch

    ; Show/hide list depending on input content and list data
    If GUICtrlRead($INPUT) <> "" And BitAND(GUICtrlGetState($LIST), $GUI_HIDE) = $GUI_HIDE And $NEW_DATA <> "|" Then GUICtrlSetState($LIST, $GUI_SHOW)
    If GUICtrlRead($INPUT) =  "" And BitAND(GUICtrlGetState($LIST), $GUI_SHOW) = $GUI_SHOW Then GUICtrlSetState($LIST, $GUI_HIDE)

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

WEnd

Func Keywords()

    ; Only items beginning with B created - so able to see what happens when list holds nothing (hides) or lots of data (scrolls)
    For $INDEX = 0 To 99
        $KEYWORD[$INDEX] = "B" & Chr(Random(65,90,1)) & Chr(Random(65,90,1)) & Chr(Random(65,90,1)) & Chr(Random(65,90,1))
        $LIST_DATA &= $KEYWORD[$INDEX] & "|"
    Next
    GUICtrlSetData($LIST,$LIST_DATA)
EndFunc

Func CheckInputText()
    $l=StringLen(guictrlread($input))
    $NEW_DATA = "|"  ; Start with delimiter so new data always replaces aold
    $READ = GUICtrlRead($INPUT)
    If $READ <> "" Then
        For $INDEX = 0 To 99
            If StringLeft($KEYWORD[$INDEX],$l) = $READ Then $NEW_DATA &= $KEYWORD[$INDEX] & "|"
        Next
        GUICtrlSetData($LIST,$NEW_DATA)
    EndIf
EndFunc

The list is only filled with items beginning with "B" so you can see what happens when the list holds lots of items and when it holds none.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
Share on other sites

Hi M..

Thanks a lot for "rejigging" the code.. I just had 1 more concern.. the listbox should be hidden as soon as choice has been made by user.. So I "re-rejigged" the code, as follows and achieved this..

(Again u can use the list.txt file attached in my 1st post)

#include <GUIConstantsEx.au3>
#include<guilistbox.au3>

Global $INPUT, $LIST, $LIST_DATA = "", $KEYWORD[100], $NEW_DATA = "|"

$MAIN = GUICreate("Example",200,400)
$INPUT = GUICtrlCreateInput("",5,5,190,20)
$LIST = GUICtrlCreateList("",5,25,190,80,BitOR(0x00100000,0x00200000))
GUICtrlSetState(-1, $GUI_HIDE)

$file=FileOpen(@ScriptDir&"\list.txt",0)
Keywords()
GUISetState(@SW_SHOW,$MAIN)

$sCurr_Input = ""

While True
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $LIST
            $sChosen = GUICtrlRead($LIST)
            If $sChosen <> "" Then 
                
                GUICtrlSetData($INPUT, $sChosen)
            EndIf
    EndSwitch

    ; Show/hide list depending on input content and list data
    If GUICtrlRead($INPUT) <> "" And BitAND(GUICtrlGetState($LIST), $GUI_HIDE) = $GUI_HIDE And $NEW_DATA <> "|"And _GUICtrlListBox_GetCount($list)>=2 Then GUICtrlSetState($LIST, $GUI_SHOW)
     If GUICtrlRead($INPUT) <> "" And BitAND(GUICtrlGetState($LIST), $GUI_SHOW) = $GUI_SHOW and _GUICtrlListBox_GetCount($list)=1 Then GUICtrlSetState($LIST, $GUI_HIDE) ;<<<<<<<<< hide listbox when choice has been made!!
    If GUICtrlRead($INPUT) =  "" And BitAND(GUICtrlGetState($LIST), $GUI_SHOW) = $GUI_SHOW  Then GUICtrlSetState($LIST, $GUI_HIDE)

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

WEnd

Func Keywords()

    ; Only items beginning with B created - so able to see what happens when list holds nothing (hides) or lots of data (scrolls)
    For $INDEX = 0 To 99
        $KEYWORD[$INDEX] = FileReadLine($file)
        $LIST_DATA &= $KEYWORD[$INDEX] & "|"
    Next
    GUICtrlSetData($LIST,$LIST_DATA)
EndFunc

Func CheckInputText()
    $l=StringLen(guictrlread($input))
    $NEW_DATA = "|"  ; Start with delimiter so new data always replaces aold
    $READ = GUICtrlRead($INPUT)
    If $READ <> "" Then
        For $INDEX = 0 To 99
            If StringLeft($KEYWORD[$INDEX],$l) = $READ Then $NEW_DATA &= $KEYWORD[$INDEX] & "|"
        Next
        GUICtrlSetData($LIST,$NEW_DATA)
    EndIf
EndFunc

but this doesn't work as intended!! still trying to check y..

Changed the code as below.. now its working just great!!

#include <GUIConstantsEx.au3>
#include<guilistbox.au3>

Global $INPUT, $LIST, $LIST_DATA = "", $KEYWORD[100], $NEW_DATA = "|",$m=0

$MAIN = GUICreate("Example",200,400)
$INPUT = GUICtrlCreateInput("",5,5,190,20)
$LIST = GUICtrlCreateList("",5,25,190,80,BitOR(0x00100000,0x00200000))
GUICtrlSetState(-1, $GUI_HIDE)

$file=FileOpen(@ScriptDir&"\list.txt",0)
Keywords()
GUISetState(@SW_SHOW,$MAIN)

$sCurr_Input = ""

While True
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $LIST
            $sChosen = GUICtrlRead($LIST)
            If $sChosen <> "" Then 
                $m=1
                sleep(250)
                GUICtrlSetData($INPUT, $sChosen)
            EndIf
    EndSwitch

    ; Show/hide list depending on input content and list data
    If GUICtrlRead($INPUT) <> "" And BitAND(GUICtrlGetState($LIST), $GUI_HIDE) = $GUI_HIDE And $NEW_DATA <> "|"And _GUICtrlListBox_GetCount($list)>=2 Then GUICtrlSetState($LIST, $GUI_SHOW)
     If GUICtrlRead($INPUT) <> "" And BitAND(GUICtrlGetState($LIST), $GUI_SHOW) = $GUI_SHOW And $m=1  Then 
         $m=0
         GUICtrlSetState($LIST, $GUI_HIDE) ;<<<<<<<<< hide listbox when choice has been made!!
         EndIf
    If GUICtrlRead($INPUT) =  "" And BitAND(GUICtrlGetState($LIST), $GUI_SHOW) = $GUI_SHOW  Then GUICtrlSetState($LIST, $GUI_HIDE)

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

WEnd

Func Keywords()

    ; Only items beginning with B created - so able to see what happens when list holds nothing (hides) or lots of data (scrolls)
    For $INDEX = 0 To 99
        $KEYWORD[$INDEX] = FileReadLine($file)
        $LIST_DATA &= $KEYWORD[$INDEX] & "|"
    Next
    GUICtrlSetData($LIST,$LIST_DATA)
EndFunc

Func CheckInputText()
    $l=StringLen(guictrlread($input))
    $NEW_DATA = "|"  ; Start with delimiter so new data always replaces aold
    $READ = GUICtrlRead($INPUT)
    If $READ <> "" Then
        For $INDEX = 0 To 99
            If StringLeft($KEYWORD[$INDEX],$l) = $READ Then $NEW_DATA &= $KEYWORD[$INDEX] & "|"
        Next
        GUICtrlSetData($LIST,$NEW_DATA)
    EndIf
EndFunc
Edited by Manjish
[font="Garamond"]Manjish Naik[/font]Engineer, Global Services - QPSHoneywell Automation India LimitedE-mail - Manjish.Naik@honeywell.com
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...