lilx Posted March 24, 2009 Share Posted March 24, 2009 (edited) Hello, I am tryin to make a gui to be used to add or delete value’s from a array. Most of it Is already done but know I have the following problem. I am tryin to figure out what command is used to know what the user have selected in my listbox. So I can find the array number en delete that array number only. Example: the user press ”pinoccio” on my listbox and the press on the button “delete selected”. It will delete “pinoccio” in my array and leave “kabouter plop|clown|banaan” in my array. I currently have this for script expandcollapse popup#include <GUIConstantsEx.au3> #include <ListboxConstants.au3> #include <GUIListBox.au3> #include <WindowsConstants.au3> #include <Array.au3> Opt('MustDeclareVars', 1) Local $MESSAGE = StringSplit("kabouter plop|clown|banaan|pinoccio " , "|") Local $FLadd, $FLclear, $FLlist, $FLmsg, $FLgui, $FLinput $FLgui = GUICreate("Filter List", 400, 385) $FLadd = GUICtrlCreateButton("Add", 310, 352, 85, 25) $FLclear = GUICtrlCreateButton("Delete Selected", 310, 6, 85, 25) $FLlist = GUICtrlCreateList("", 5, 5, 300, 350) $FLinput = GUICtrlCreateInput("", 5, 355, 300, 20) ; will not accept drag&drop files ;GUICtrlSetLimit($FLlist, 200) ; to limit horizontal scrolling For $i = 1 to $MESSAGE[0] GUICtrlSetData($FLlist, $MESSAGE[$i]) Next GUISetState() While 1 $FLmsg = GUIGetMsg() Select Case $FLmsg = $GUI_EVENT_CLOSE Exit Case $FLmsg = $FLadd _ArrayAdd($MESSAGE, GUICtrlRead($FLinput)) _GUICtrlListBox_BeginUpdate($FLlist) _GUICtrlListBox_AddString($FLlist, GUICtrlRead($FLinput)) _GUICtrlListBox_UpdateHScroll($FLlist) _GUICtrlListBox_EndUpdate($FLlist) $MESSAGE[0] = $MESSAGE[0] + 1 ;_ArrayDisplay($MESSAGE, "Updated Array") Case $FLmsg = $FLclear EndSelect WEnd Edited March 24, 2009 by lilx Link to comment Share on other sites More sharing options...
Mat Posted March 24, 2009 Share Posted March 24, 2009 expandcollapse popup#include <GUIConstantsEx.au3> #include <ListboxConstants.au3> #include <GUIListBox.au3> #include <WindowsConstants.au3> #include <Array.au3> Opt('MustDeclareVars', 1) Local $MESSAGE = StringSplit("kabouter plop|clown|banaan|pinoccio " , "|") Local $FLadd, $FLclear, $FLlist, $FLmsg, $FLgui, $FLinput, $Selected $FLgui = GUICreate("Filter List", 400, 385) $FLadd = GUICtrlCreateButton("Add", 310, 352, 85, 25) $FLclear = GUICtrlCreateButton("Delete Selected", 310, 6, 85, 25) $FLlist = GUICtrlCreateList("", 5, 5, 300, 350) $FLinput = GUICtrlCreateInput("", 5, 355, 300, 20) ; will not accept drag&drop files ;GUICtrlSetLimit($FLlist, 200) ; to limit horizontal scrolling For $i = 1 to $MESSAGE[0] GUICtrlSetData($FLlist, $MESSAGE[$i]) Next GUISetState() While 1 $FLmsg = GUIGetMsg() Select Case $FLmsg = $GUI_EVENT_CLOSE Exit Case $FLmsg = $FLadd _ArrayAdd($MESSAGE, GUICtrlRead($FLinput)) _GUICtrlListBox_BeginUpdate($FLlist) _GUICtrlListBox_AddString($FLlist, GUICtrlRead($FLinput)) _GUICtrlListBox_UpdateHScroll($FLlist) _GUICtrlListBox_EndUpdate($FLlist) $MESSAGE[0] = $MESSAGE[0] + 1 ;_ArrayDisplay($MESSAGE, "Updated Array") Case $FLmsg = $FLclear $Selected = _GUICtrlListBox_GetCurSel($FLlist) _GUICtrlListBox_DeleteString($FLlist, $selected) EndSelect WEnd AutoIt Project Listing Link to comment Share on other sites More sharing options...
DaRam Posted March 24, 2009 Share Posted March 24, 2009 ; Get indexes of selected items $aItems = _GUICtrlListBox_GetSelItems($FLlist) Link to comment Share on other sites More sharing options...
lilx Posted March 24, 2009 Author Share Posted March 24, 2009 (edited) aha thank you very much. i went true almost all _GUICtrlListBox and just couldn't see/find it now just deleted it out of my array and done , but that i can do myself Edited March 24, 2009 by lilx Link to comment Share on other sites More sharing options...
Mat Posted March 24, 2009 Share Posted March 24, 2009 No probs I don't think it works for multiple selections though, so if you want that use darams one, It works for more than 1 selecion. MDiesel AutoIt Project Listing Link to comment Share on other sites More sharing options...
lilx Posted March 24, 2009 Author Share Posted March 24, 2009 btw a other question outside the topic subject, but question isn't serious enough to start new topic. i am using for this module string split. i know that a string have a maximum string length of 2147483647 characters but AutoIt script can only have 4095 characters. is this maxium the same for stringsplit? or is the maximum of stringsplit less? Link to comment Share on other sites More sharing options...
lilx Posted March 24, 2009 Author Share Posted March 24, 2009 No probsI don't think it works for multiple selections though, so if you want that use darams one, It works for more than 1 selecion.MDieselto avoid problems is it possible then to limit the selection to one at a time? Link to comment Share on other sites More sharing options...
Mat Posted March 24, 2009 Share Posted March 24, 2009 to avoid problems is it possible then to limit the selection to one at a time?I think that is default - It is in your script anyway - it was just an idea incase you wanted to include that. AutoIt Project Listing Link to comment Share on other sites More sharing options...
lilx Posted March 24, 2009 Author Share Posted March 24, 2009 well i thought i would have no problems with the array stuff but i have it , i am getting at the arraysearch a -1 return. meaning my variable isn't a array wich i don't get... expandcollapse popup#include <GUIConstantsEx.au3> #include <ListboxConstants.au3> #include <GUIListBox.au3> #include <WindowsConstants.au3> #include <Array.au3> Opt('MustDeclareVars', 1) Local $MESSAGE = StringSplit("kabouter plop|clown|banaan|pinoccio" , "|") Local $FLadd, $FLclear, $FLlist, $FLmsg, $FLgui, $FLinput, $FLindex, $FLtext, $FLpos $FLgui = GUICreate("Filter List", 400, 385) $FLadd = GUICtrlCreateButton("Add", 310, 352, 85, 25) $FLclear = GUICtrlCreateButton("Delete Selected", 310, 6, 85, 25) $FLlist = GUICtrlCreateList("", 5, 5, 300, 350) $FLinput = GUICtrlCreateInput("", 5, 355, 300, 20) ; will not accept drag&drop files ;GUICtrlSetLimit($FLlist, 200) ; to limit horizontal scrolling For $i = 1 to $MESSAGE[0] GUICtrlSetData($FLlist, $MESSAGE[$i]) Next GUISetState() While 1 $FLmsg = GUIGetMsg() Select Case $FLmsg = $GUI_EVENT_CLOSE Exit Case $FLmsg = $FLadd _ArrayAdd($MESSAGE, GUICtrlRead($FLinput)) _GUICtrlListBox_BeginUpdate($FLlist) _GUICtrlListBox_AddString($FLlist, GUICtrlRead($FLinput)) _GUICtrlListBox_UpdateHScroll($FLlist) _GUICtrlListBox_EndUpdate($FLlist) $MESSAGE[0] = $MESSAGE[0] + 1 _ArrayDisplay($MESSAGE, "Updated Array") Case $FLmsg = $FLclear $FLindex = _GUICtrlListBox_GetCurSel($FLlist) $FLtext = _GUICtrlListBox_GetText($FLlist, $FLindex) MsgBox ( 48, "test1", $FLtext ) $FLpos = _ArraySearch($FLlist, $FLtext, 0, 0, 0, 1) ; getting -1 error here? MsgBox ( 48, "test2", $FLpos ) _ArrayDelete($FLlist, $FLpos) $MESSAGE[0] = $MESSAGE[0] - 1 _GUICtrlListBox_DeleteString($FLlist, $FLindex) _ArrayDisplay($MESSAGE, "Updated Array") EndSelect WEnd Link to comment Share on other sites More sharing options...
Aceguy Posted March 24, 2009 Share Posted March 24, 2009 (edited) you had a mix up between your arrays, study this code, and learn from your mistakes..... i have only updated your delete func, youll need to change your add func to make it work.... you were searching in the array $FLlist whcih is the listbox, not the array that contains the data $MESSAGE expandcollapse popup#include <GUIConstantsEx.au3> #include <ListboxConstants.au3> #include <GUIListBox.au3> #include <WindowsConstants.au3> #include <Array.au3> $MESSAGE = StringSplit("kabouter plop|clown|banaan|pinoccio", "|") $FLgui = GUICreate("Filter List", 400, 385) $FLadd = GUICtrlCreateButton("Add", 310, 352, 85, 25) $FLclear = GUICtrlCreateButton("Delete Selected", 310, 6, 85, 25) $FLlist = GUICtrlCreateList("", 5, 5, 300, 350) $FLinput = GUICtrlCreateInput("", 5, 355, 300, 20) ; will not accept drag&drop files ;GUICtrlSetLimit($FLlist, 200) ; to limit horizontal scrolling For $i = 1 To $MESSAGE[0] GUICtrlSetData($FLlist, $MESSAGE[$i]) Next GUISetState() While 1 $FLmsg = GUIGetMsg() Select Case $FLmsg = $GUI_EVENT_CLOSE Exit Case $FLmsg = $FLadd _ArrayAdd($MESSAGE, GUICtrlRead($FLinput)) _GUICtrlListBox_BeginUpdate($FLlist) _GUICtrlListBox_AddString($FLlist, GUICtrlRead($FLinput)) _GUICtrlListBox_UpdateHScroll($FLlist) _GUICtrlListBox_EndUpdate($FLlist) $MESSAGE[0] = $MESSAGE[0] + 1 _ArrayDisplay($MESSAGE, "Updated Array") Case $FLmsg = $FLclear $FLindex = _GUICtrlListBox_GetCurSel($FLlist) $FLtext = _GUICtrlListBox_GetText($FLlist, $FLindex) $FLpos = _ArraySearch($MESSAGE, $FLtext, 1, 0, 0, 0, 1, 0) ConsoleWrite("pos " & $FLpos & @LF) _ArrayDelete($MESSAGE, $FLpos) $MESSAGE[0] = UBound($MESSAGE) - 1 _GUICtrlListBox_DeleteString($FLlist, $FLindex) _ArrayDisplay($MESSAGE, "After Deletion") EndSelect WEnd Edited March 24, 2009 by Aceguy [u]My Projects.[/u]Launcher - not just for games & Apps (Mp3's & Network Files)Mp3 File RenamerMy File Backup UtilityFFXI - Realtime to Vana time Clock Link to comment Share on other sites More sharing options...
lilx Posted March 24, 2009 Author Share Posted March 24, 2009 you had a mix up between your arrays, study this code, and learn from your mistakes..... i have only updated your delete func, youll need to change your add func to make it work.... you were searching in the array $FLlist whcih is the listbox, not the array that contains the data $MESSAGE expandcollapse popup#include <GUIConstantsEx.au3> #include <ListboxConstants.au3> #include <GUIListBox.au3> #include <WindowsConstants.au3> #include <Array.au3> $MESSAGE = StringSplit("kabouter plop|clown|banaan|pinoccio", "|") $FLgui = GUICreate("Filter List", 400, 385) $FLadd = GUICtrlCreateButton("Add", 310, 352, 85, 25) $FLclear = GUICtrlCreateButton("Delete Selected", 310, 6, 85, 25) $FLlist = GUICtrlCreateList("", 5, 5, 300, 350) $FLinput = GUICtrlCreateInput("", 5, 355, 300, 20) ; will not accept drag&drop files ;GUICtrlSetLimit($FLlist, 200) ; to limit horizontal scrolling For $i = 1 To $MESSAGE[0] GUICtrlSetData($FLlist, $MESSAGE[$i]) Next GUISetState() While 1 $FLmsg = GUIGetMsg() Select Case $FLmsg = $GUI_EVENT_CLOSE Exit Case $FLmsg = $FLadd _ArrayAdd($MESSAGE, GUICtrlRead($FLinput)) _GUICtrlListBox_BeginUpdate($FLlist) _GUICtrlListBox_AddString($FLlist, GUICtrlRead($FLinput)) _GUICtrlListBox_UpdateHScroll($FLlist) _GUICtrlListBox_EndUpdate($FLlist) $MESSAGE[0] = $MESSAGE[0] + 1 _ArrayDisplay($MESSAGE, "Updated Array") Case $FLmsg = $FLclear $FLindex = _GUICtrlListBox_GetCurSel($FLlist) $FLtext = _GUICtrlListBox_GetText($FLlist, $FLindex) $FLpos = _ArraySearch($MESSAGE, $FLtext, 1, 0, 0, 0, 1, 0) ConsoleWrite("pos " & $FLpos & @LF) _ArrayDelete($MESSAGE, $FLpos) $MESSAGE[0] = UBound($MESSAGE) - 1 _GUICtrlListBox_DeleteString($FLlist, $FLindex) _ArrayDisplay($MESSAGE, "After Deletion") EndSelect WEnd hi, and thank you for the responce, i indeed sometimes make those mistakes. but offent when i am working the code or the problem for longer time you see things over head. and thats why i posted it so a pair of fresh eyes can take a look at it 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