Maniacwithit

Making '*' as any group of signs from a list

7 posts in this topic

Hello,

I have a list for example:

1. boring noses

2. bricking wall

3. balley vall

4. crowded lifts

etc...

and I want to search in it by typing something like 'b* n' and i would like it to automatically change to 'boring noses'. Can somebody help me with this problem, pls?

Share this post


Link to post
Share on other sites



Yes, I want to use it to fill a window in a program

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

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


Global $hGUI, $hInput, $hList, $sPartialData, $asCities, $sAllCities, $iCurrIndex

$hGUI = GUICreate("Miasta", 200, 400,-1,-1,bitor($WS_BORDER,$WS_POPUP))
$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)

; Create list full of random 12 character "words"
FillList()

; 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)
                msgbox(0,"",UBound($asCities))
                If _ArraySearch($asCities, $sFinal) > 0 Then
                    MsgBox(0, "Chosen", $sFinal)
                EndIf
            EndIf
        Case $hUP
            $iCurrIndex -= 1
            If $iCurrIndex < 0 Then $iCurrIndex = 0
            _GUICtrlListBox_SetCurSel($hList, $iCurrIndex)
         Case $hDOWN
            $iTotal = _GUICtrlListBox_GetCount($hList)
            $iCurrIndex += 1
            If $iCurrIndex > $iTotal - 1 Then $iCurrIndex = $iTotal - 1
            _GUICtrlListBox_SetCurSel($hList, $iCurrIndex)
        Case $hENTER
            if $iCurrIndex = -1 Then $iCurrIndex = 0

            ;$sText = _GUICtrlListBox_GetText($hList, $iCurrIndex)
            ;GUICtrlSetData($hInput, $sText)
            ;$iCurrIndex = -1
            _GUICtrlListBox_SetCurSel($hList, $iCurrIndex)
    EndSwitch

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

;filters list with matching values
Func UpdateList()
    $sPartialData = "|" ; Start with delimiter so new data always replaces old
    Local $sInput = GUICtrlRead($hInput)

   ;$sInput = StringReplace($sInput,"*",".*"); this thing works in Autohotkey version
   ;$sInput = StringUpper($sInput)

    If $sInput <> "" Then
        For $i = 0 To UBound($asCities) -1
            If Stringinstr($asCities[$i], $sInput) = 1  Then $sPartialData &= $asCities[$i] & "|"

            ; below is my code, bot it works not well
            ;If StringRegExp($asCities[$i], $sInput) <> 0  Then $sPartialData &= $asCities[$i] & "|"
        Next
     Else
        $sPartialData = $sAllCities
        $iCurrIndex = -1
     EndIf
     GUICtrlSetData($hList, $sPartialData)
EndFunc   ;==>UpdateList


;reads Cities from file and loads to ListBox
Func FillList()

   $sAllCities = "|"
   $file = "miasta.txt"

   _FileReadToArray($file, $asCities)
   _ArraySort($asCities)
   For $i = 1 to UBound($asCities) -1
      $sAllCities &= $asCities[$i] & "|"
   Next

    GUICtrlSetData($hList, $sAllCities)
    $iCurrIndex = -1
    _GUICtrlListBox_SetCurSel($hList, $iCurrIndex)

EndFunc   ;==>FillList

 

Edited by Melba23
Added code tags

Share this post


Link to post
Share on other sites

Hi all,

After a PM exchange with the OP this is definitely not a game, so there was no need to report it.

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

I wonder if this would work for you and maybe add in some tweaking so that * is converted into .* for regex.

 

It may not plug right into your code, but the concept should work.

 

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