Garp99HasSpoken Posted February 11, 2013 Share Posted February 11, 2013 (edited) I'm having a problem with two lists to update. A populated volunteer list on the right and an empty worker list on the left. The idea is to Add a worker from volunteer list into the worker list and this should remove that selection from the volunteer list so that they cannot be selected again. So at all times, the worker + volunteer lists should equal the starting volunteer list. And Removing a worker from the list will add them back into the volunteer list. The code below runs but even though MsgBox is returning values, the lists are not being updated properly. When I add a worker, the volunteer list still shows them and in fact the list is duplicated (2 copies). When I add second worker, I get WorkerA and WorkerAWorkerB in the list, and now volunteer list is 3 copies. When removing WorkerA, they remain in the list. I'm fairly certain my regexp is good 'cause I tested it with RegExp.exe program. What have I missed? expandcollapse popup#include <ButtonConstants.au3> #include <DateTimeConstants.au3> #include <GUIConstantsEx.au3> #include <GUIListBox.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <GuiMonthCal.au3> #include <Array.au3> Opt("GUIOnEventMode", 1) Global $defVolunteer = "Bob Barker" Local $workers, $volunteers ClrEvent() #Region ### START Koda GUI section ### Form=r:\autoit examples\koda\forms\volunteeraddevent.kxf Local $FormAddEvent = GUICreate("Add Event", 422, 481, 302, 137) GUISetFont(12, 400, 0, "MS Sans Serif") GUISetBkColor(0xA6CAF0) GUISetOnEvent($GUI_EVENT_CLOSE, "FormAddEventClose") GUISetOnEvent($GUI_EVENT_MINIMIZE, "") GUISetOnEvent($GUI_EVENT_MAXIMIZE, "") GUISetOnEvent($GUI_EVENT_RESTORE, "") GUICtrlCreateLabel("Volunteer(s):", 160, 200, 112, 28, 0) GUICtrlSetFont(-1, 14, 400, 0, "MS Sans Serif") Local $VolWorked = GUICtrlCreateList("", 24, 176, 129, 246, BitOR($LBS_NOTIFY,$LBS_SORT,$WS_BORDER)) GUICtrlSetResizing(-1, $GUI_DOCKHEIGHT) Local $ButtonAdd = GUICtrlCreateButton("<< &Add", 168, 256, 97, 33, $BS_NOTIFY) GUICtrlSetOnEvent(-1, "ButtonAddClick") Local $ButtonRemove = GUICtrlCreateButton("&Remove >>", 168, 312, 97, 33, $BS_NOTIFY) GUICtrlSetOnEvent(-1, "ButtonRemoveClick") Local $VolList = GUICtrlCreateList("", 272, 176, 129, 246, BitOR($LBS_NOTIFY,$LBS_SORT,$WS_BORDER)) GUICtrlSetData(-1, $volunteers, $defVolunteer) GUICtrlSetResizing(-1, $GUI_DOCKHEIGHT) Local $ButtonEventDone = GUICtrlCreateButton("&Done", 90, 432, 97, 40, $BS_NOTIFY) GUICtrlSetOnEvent(-1, "ButtonEventDoneClick") Local $ButtonEventCancel = GUICtrlCreateButton("&Cancel", 235, 432, 97, 40, $BS_NOTIFY) GUICtrlSetOnEvent(-1, "ButtonEventCancelClick") GUISetState(@SW_HIDE) #EndRegion ### END Koda GUI section ### Func ClrEvent() $workers = "" $volunteers = "Bob Barker|Al Muh|Noele Muh|Carol Tartin|Don Floods|Lora Floods" EndFunc Func FormAddEventClose() GUISetState(@SW_HIDE) Exit EndFunc Func ButtonEventCancelClick() if (MsgBox(36, "Are You Sure?", "Cancel all changes and exit?") = 6) Then FormAddEventClose() EndFunc Func ButtonEventDoneClick() If (StringLen($workers) = 0) Then MsgBox(16, "Missing Workers", "A volunteer must be added to the list on the left." & @CRLF & "Select from Volunteer list on right and use the Add button.", 10) Else MsgBox(0, "Results", "Workers: " & $workers & @CRLF & @CRLF) EndIf EndFunc Func ButtonAddClick() Local $picked = GUICtrlRead($VolList) ; MsgBox(0, "Adding Before", "Worker picked: " & $picked & @CRLF & @CRLF & "Volunteer list: " & $volunteers & @CRLF & @CRLF, 10) $workers &= $picked StringRegExpReplace($volunteers, "(\|" & $picked & "$)", "") ; remove last item matched StringRegExpReplace($volunteers, "(" & $picked & "\|)", "") ; remove anywhere else GUICtrlSetData($VolList, $volunteers) GUICtrlSetData($VolWorked, $workers) MsgBox(0, "Adding Worker", "Worker picked: " & $picked & @CRLF & @CRLF & "Volunteer list: " & $volunteers & @CRLF & @CRLF, 10) EndFunc Func ButtonRemoveClick() Local $picked = GUICtrlRead($VolWorked) MsgBox(0, "Removing Before", "Volunteer removed: " & $picked & @CRLF & @CRLF & "Worker list: " & $workers & @CRLF & @CRLF, 10) $volunteers &= $picked StringRegExpReplace($workers, "(\|" & $picked & "$)", "") StringRegExpReplace($workers, "(" & $picked & "\|)", "") GUICtrlSetData($VolList, $volunteers) GUICtrlSetData($VolWorked, $workers) MsgBox(0, "Removing Worker", "Volunteer removed: " & $picked & @CRLF & @CRLF & "Worker list: " & $workers & @CRLF & @CRLF, 10) EndFunc GUISetState(@SW_SHOW) Local $msg While 1 $msg=GUIGetMsg() If (($msg = $GUI_EVENT_CLOSE) Or ($msg = $ButtonEventDone) Or ($msg = $ButtonEventCancel)) Then ExitLoop WEnd GUISetState(@SW_HIDE) GUIDelete() Exit Edited February 12, 2013 by Garp99HasSpoken Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 11, 2013 Moderators Share Posted February 11, 2013 Garp99HasSpoken,You need to assign the result of the StringRegExpReplace operation to a variable if you want to see the result - you were not doing this. And you do not need a regex for something like this - a simple StringReplace will do. Taker a look at this modified version of your script:expandcollapse popup#include <ButtonConstants.au3> #include <DateTimeConstants.au3> #include <GUIConstantsEx.au3> #include <GUIListBox.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <GuiMonthCal.au3> #include <Array.au3> Opt("GUIOnEventMode", 1) Global $defVolunteer = "Bob Barker" Local $workers, $volunteers ClrEvent() #Region ### START Koda GUI section ### Form=r:\autoit examples\koda\forms\volunteeraddevent.kxf Local $FormAddEvent = GUICreate("Add Event", 422, 481, 302, 137) GUISetFont(12, 400, 0, "MS Sans Serif") GUISetBkColor(0xA6CAF0) GUISetOnEvent($GUI_EVENT_CLOSE, "FormAddEventClose") GUISetOnEvent($GUI_EVENT_MINIMIZE, "") GUISetOnEvent($GUI_EVENT_MAXIMIZE, "") GUISetOnEvent($GUI_EVENT_RESTORE, "") GUICtrlCreateLabel("Volunteer(s):", 160, 200, 112, 28, 0) GUICtrlSetFont(-1, 14, 400, 0, "MS Sans Serif") Local $VolWorked = GUICtrlCreateList("", 24, 176, 129, 246, BitOR($LBS_NOTIFY, $LBS_SORT, $WS_BORDER)) GUICtrlSetResizing(-1, $GUI_DOCKHEIGHT) Local $ButtonAdd = GUICtrlCreateButton("<< &Add", 168, 256, 97, 33, $BS_NOTIFY) GUICtrlSetOnEvent(-1, "ButtonAddClick") Local $ButtonRemove = GUICtrlCreateButton("&Remove >>", 168, 312, 97, 33, $BS_NOTIFY) GUICtrlSetOnEvent(-1, "ButtonRemoveClick") Local $VolList = GUICtrlCreateList("", 272, 176, 129, 246, BitOR($LBS_NOTIFY, $LBS_SORT, $WS_BORDER)) GUICtrlSetData(-1, $volunteers, $defVolunteer) GUICtrlSetResizing(-1, $GUI_DOCKHEIGHT) Local $ButtonEventDone = GUICtrlCreateButton("&Done", 90, 432, 97, 40, $BS_NOTIFY) GUICtrlSetOnEvent(-1, "ButtonEventDoneClick") Local $ButtonEventCancel = GUICtrlCreateButton("&Cancel", 235, 432, 97, 40, $BS_NOTIFY) GUICtrlSetOnEvent(-1, "ButtonEventCancelClick") GUISetState(@SW_HIDE) #EndRegion ### END Koda GUI section ### Func ClrEvent() $workers = "" $volunteers = "|Bob Barker|Al Muh|Noele Muh|Carol Tartin|Don Floods|Lora Floods" EndFunc ;==>ClrEvent Func FormAddEventClose() GUISetState(@SW_HIDE) Exit EndFunc ;==>FormAddEventClose Func ButtonEventCancelClick() If (MsgBox(36, "Are You Sure?", "Cancel all changes and exit?") = 6) Then FormAddEventClose() EndFunc ;==>ButtonEventCancelClick Func ButtonEventDoneClick() If (StringLen($workers) = 0) Then MsgBox(16, "Missing Workers", "A volunteer must be added to the list on the left." & @CRLF & "Select from Volunteer list on right and use the Add button.", 10) Else MsgBox(0, "Results", "Workers: " & $workers & @CRLF & @CRLF) EndIf EndFunc ;==>ButtonEventDoneClick Func ButtonAddClick() Local $picked = GUICtrlRead($VolList) MsgBox(0, "Adding Before", "Worker picked: " & $picked & @CRLF & @CRLF & "Volunteer list: " & $volunteers & @CRLF & @CRLF, 10) ; Add the name to the relevant list $workers &= "|" & $picked ; Remove it from the other $volunteers = StringReplace($volunteers, "|" & $picked, "") ; And reload the lists GUICtrlSetData($VolList, $volunteers) GUICtrlSetData($VolWorked, $workers) MsgBox(0, "Adding Worker", "Worker picked: " & $picked & @CRLF & @CRLF & "Volunteer list: " & $volunteers & @CRLF & @CRLF, 10) EndFunc ;==>ButtonAddClick Func ButtonRemoveClick() Local $picked = GUICtrlRead($VolWorked) MsgBox(0, "Removing Before", "Volunteer removed: " & $picked & @CRLF & @CRLF & "Worker list: " & $workers & @CRLF & @CRLF, 10) $volunteers &= "|" & $picked $workers = StringReplace($workers, "|" & $picked, "") GUICtrlSetData($VolList, $volunteers) GUICtrlSetData($VolWorked, $workers) MsgBox(0, "Removing Worker", "Volunteer removed: " & $picked & @CRLF & @CRLF & "Worker list: " & $workers & @CRLF & @CRLF, 10) EndFunc ;==>ButtonRemoveClick GUISetState(@SW_SHOW) Local $msg While 1 $msg = GUIGetMsg() If (($msg = $GUI_EVENT_CLOSE) Or ($msg = $ButtonEventDone) Or ($msg = $ButtonEventCancel)) Then ExitLoop WEnd GUISetState(@SW_HIDE) GUIDelete() ExitPlease ask if you have any questions. 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...
Garp99HasSpoken Posted February 11, 2013 Author Share Posted February 11, 2013 Thanks a lot, it works as expected. At least I wasn't too far off... can't believe I forgot to pre-append the "|" when adding an item to the list. The big thing I didn't understand was how adding "|" to the beginning of the list is ok and doesn't cause an empty line. But now I know. 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