Jump to content

Input box with suggested entries


c.haslam
 Share

Recommended Posts

I have a dialog box with an inputbox control. I wish to be prompted for my entry as (e.g.) Firefox does. For example, if I have previously entered my City as Montreal, when I enter Mon, Firefox suggests Montreal.

Is this possible in AutoIt? If so, how?

...chris

Spoiler

CDebug Dumps values of variables including arrays and DLL structs, to a GUI, to the Console, and to the Clipboard

 

Link to comment
Share on other sites

If you want your script to remember past entries, then the best thing to do is to either write them to a file (.ini) or to the registry.

Then, you can simply compare what the user has typed with each entry, and have it pull out the one(s) that contain the letters they have typed so far.

Link to comment
Share on other sites

paulie...hes asking that for example...if he types: mon...in the box...it will popup with a suggestion: Montreal, Monitor, Money....etc...if this is what hes asking..

oops got the wrong...idea...good job paulie :D you are correct :P

Edited by Swift
Link to comment
Share on other sites

I have set up a very lame and buggy example...

#include <GuiConstants.au3>
Opt('GuiOnEventMode',1)
    IniWrite(@TempDir&"\entries.ini", "Entries", "1", "Monkey")
    IniWrite(@TempDir&"\entries.ini", "Entries", "2", "Money")
    IniWrite(@TempDir&"\entries.ini", "Entries", "3", "Dog")
    IniWrite(@TempDir&"\entries.ini", "Entries", "4", "Montreal")
    IniWrite(@TempDir&"\entries.ini", "Entries", "5", "Cat")

$GUI = GUICreate("Memory Test", 300, 100)
$Input = GUICtrlCreateInput("", 75, 35, 150, 20)
GUICtrlSetOnEvent(-1, "CheckFile")
GUISetState()

While 1
    Sleep(100)
WEnd

Func CheckFile()
    If FileExists(@TempDir&"\entries.ini") Then
        $array=IniReadSection(@TempDir&"\entries.ini", "Entries")
        Dim $Contents[$array[0][0]+1]
        For $i = 1 to $array[0][0]
            $Contents[$i] = $array[$i][1]
        Next
        Dim $ValidStrings[1],$count=0,$Text=""
        For $a in $Contents
            If StringRegExp($a, "\A("&GUICtrlRead($Input)&")",0) Then
                $count+=1
                ReDim $ValidStrings[$count]
                $ValidStrings[$count-1] = $a
            EndIf
        Next
        For $b = 0 to Ubound($ValidStrings)-1
            $Text&=$ValidStrings[$b]&@CRLF
        Next
        MsgBox(0,"",$Text)
    EndIf
EndFunc

Now, type the word "Mon" into the box, and press enter.

You should see all the words that begin with "Mon" appear in the Msgbox, but not any of the other ones.

Word used in example are:

Monkey

Money

Dog

Montreal

Cat

So if you type "C" and press enter you should get "Cat"

"D" Should Get Dog

Good Luck!

Edited by Paulie
Link to comment
Share on other sites

I accept that a file is a good place to keep valid entries.

But what I want to have happen is as follows. The user starts typing: he presses an M, an o and then an n. Without him pressing Enter, the AutoIt script would pop up a suggestion: Montreal. The user can then click on this suggestion or keeping typing. He might want to enter a city that is not in the file; for example, Monmouth. (The fully developed script would add Monmouth to the file -- for next time.)

For the foregoing to happen, the script has to be able to read the text in the inputbox whenever an alphanumeric key is pressed. Is AutoIt able to do this? In the script Paulie provided, my understanding is that GUICtrlSetOnEvent() sets up CheckFile() to be executed only when Enter is pressed. Hopefully I am wrong, or there is another mechanism for having CheckFile() executed whenever an alphanumeric key, Delete or Backspace is pressed.

...chris

Edited by c.haslam
Spoiler

CDebug Dumps values of variables including arrays and DLL structs, to a GUI, to the Console, and to the Clipboard

 

Link to comment
Share on other sites

your looking for an autocomplete. I'm sure with a loop you could get it to read an input to actually do that on every loop. I don't think you'd want to read a file on every loop though. The combobox already has the option for an autocomplete (_GUICtrlComboAutoComplete ). Could you use a combobox instead?

Link to comment
Share on other sites

Try this?

#include <GUIComboBox.au3>

Opt('MustDeclareVars', 1)

$Debug_CB = False; Check ClassName being passed to ComboBox/ComboBoxEx functions, set to True and use a handle to another control to see it work

Global $hCombo

Example_Internal()

Func Example_Internal()
    Local $hGUI

   ; Create GUI
    $hGUI = GUICreate("(Internal) ComboBox Auto Complete", 400, 296)
    $hCombo = GUICtrlCreateCombo("", 2, 2, 396, 20, BitOR ($CBS_NOINTEGRALHEIGHT, $CBS_SIMPLE))
    GUISetState()

   ; Add files
    _GUICtrlComboBox_BeginUpdate ($hCombo)
    _GUICtrlComboBox_AddDir ($hCombo, @WindowsDir & "\*.exe")
    _GUICtrlComboBox_EndUpdate ($hCombo)

    GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")

   ; Loop until user exits
    Do
        Sleep (10)
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
    GUIDelete()
EndFunc  ;==>Example_Internal

Func _Edit_Changed()
    _GUICtrlComboBox_AutoComplete ($hCombo)
EndFunc  ;==>_Edit_Changed

Func WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam)
    Local $hWndFrom, $iIDFrom, $iCode, $hWndCombo
    If Not IsHWnd($hCombo) Then $hWndCombo = GUICtrlGetHandle($hCombo)
    $hWndFrom = $ilParam
    $iIDFrom = BitAND($iwParam, 0xFFFF); Low Word
    $iCode = BitShift($iwParam, 16); Hi Word
    Switch $hWndFrom
        Case $hCombo, $hWndCombo
            Switch $iCode
                Case $CBN_EDITCHANGE; Sent after the user has taken an action that may have altered the text in the edit control portion of a combo box
                    _Edit_Changed()
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc  ;==>WM_COMMAND

Making a Combo into a text box looking thing... Ughhh... But it works :D

Link to comment
Share on other sites

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