topten Posted August 22, 2015 Share Posted August 22, 2015 I have a list of words$a[0]="bob"$a[1]="betty"$a[2]="cindy'$a[3]="cherry"How can I perform sorting by letter? for example by letter "b", then I hav as a result only "bob" and "betty" or by letters "be" then I have only "betty". How to do it programmatically? Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted August 22, 2015 Moderators Share Posted August 22, 2015 topten,This old script of mine should give you some ideas - it takes a list of random 4-letter "words" and selects those which match the letters entered into the edit:expandcollapse popup#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 ;==>KeywordsLet me know if I can help adapt it to meet your specific requirements.M23 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Danyfirex Posted August 22, 2015 Share Posted August 22, 2015 I wrote this simple example.#include <Array.au3> Local $a = ["bob", "betty", "cindy", "cherry"] Local $aNewArray = 0 _ArrayDisplay($a) $aNewArray = _GetArrayByletter($a, "b") _ArrayDisplay($aNewArray) $aNewArray = _GetArrayByletter($a, "ci") _ArrayDisplay($aNewArray) $aNewArray = _GetArrayByletter($a, "be") _ArrayDisplay($aNewArray) Func _GetArrayByletter($Array, $Letter) Local $aReturn[0] If IsArray($Array) Then For $i = 0 To UBound($Array) - 1 If StringInStr($Array[$i], $Letter) = 1 Then ReDim $aReturn[UBound($aReturn) + 1] $aReturn[UBound($aReturn) - 1] = $Array[$i] EndIf Next EndIf If UBound($aReturn) = 0 Then $aReturn = 0 Return $aReturn EndFunc ;==>_GetArrayByletter Saludos Danysys.com AutoIt... UDFs: VirusTotal API 2.0 UDF - libZPlay UDF - Apps: Guitar Tab Tester - VirusTotal Hash Checker Examples: Text-to-Speech ISpVoice Interface - Get installed applications - Enable/Disable Network connection PrintHookProc - WINTRUST - Mute Microphone Level - Get Connected NetWorks - Create NetWork Connection ShortCut Link to comment Share on other sites More sharing options...
topten Posted August 24, 2015 Author Share Posted August 24, 2015 Thanx a lot , that works fine! Link to comment Share on other sites More sharing options...
kylomas Posted August 25, 2015 Share Posted August 25, 2015 bored...expandcollapse popup#include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <array.au3> #include <string.au3> #AutoIt3Wrapper_Add_Constants=n Local $hGui010 = GUICreate('', 230, 250) GUICtrlCreateLabel('Search Argument:', 10, 20, 110, 20, $SS_CENTERIMAGE) GUICtrlSetFont(-1, 9, 800) Local $cInp010 = GUICtrlCreateInput('', 120, 20, 100, 20) Local $cLst010 = GUICtrlCreateList('', 120, 50, 100, 200) Local $cWrd010 = GUICtrlCreateLabel('', 10, 52, 100, 184, BitOR($ss_sunken, $ss_center)) GUICtrlSetFont(-1, 9, 800) GUICtrlSetColor(-1, 0xfafafa) GUISetState() Local $sWordList = 'Ann Jack house green turtle coffee Agamemnon eloquent hubris chortle aggregate jamboree' Local $save_last_input GUICtrlSetData($cWrd010, stringreplace($sWordList, ' ', @CRLF)) local $atmp While 1 Switch GUIGetMsg() Case $gui_event_close Exit EndSwitch If $save_last_input <> GUICtrlRead($cInp010) Then $save_last_input = GUICtrlRead($cInp010) if stringlen($save_last_input) = 0 then guictrlsetdata($cLst010,'') continueloop endif $atmp = StringRegExp($sWordList, '(?i)\b' & $save_last_input & '(?:\w+)?\b', 3) GUICtrlSetData($cLst010, ( @error ) ? '' : '|' & _ArrayToString($atmp, '|')) EndIf WEnd Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now