MuffettsMan Posted May 5, 2006 Share Posted May 5, 2006 Looking to make a basic add / remove list box like... #include <GUIConstants.au3 ; == GUI generated with Koda ==); $Form5 = GUICreate("Form1", 405, 269, 227, 154) $List1 = GUICtrlCreateList("", 16, 32, 129, 227) GUICtrlSetData($List1,"Item 1|Item 2|Item 3|Item 4") $GUI_AddButton = GUICtrlCreateButton("Add >>", 152, 88, 97, 25, 0) GUICtrlSetState($GUI_AddButton,$GUI_FOCUS) $GUI_CloseButton = GUICtrlCreateButton("<< Remove", 152, 152, 97, 25, 0) $List2 = GUICtrlCreateList("", 256, 32, 129, 227) GUISetState(@SW_SHOW) While 1 $msg = GuiGetMsg() Select case $msg = $GUI_AddButton GUICtrlSetData($List2,GUICtrlRead($List1)) Case Else Case $msg = $GUI_EVENT_CLOSE ExitLoop Case Else ;;;;;;; EndSelect WEnd ...where obviously add would move from left to right and remove would move from right to left. my quick question while i continue to tinker is am i gonna have to use regex to rebuild each list when i remove an item from one to put it in the other? (to be more specific once i click add i don't want to see Item 1 in the left list anymore it should be only in the right and when hitting remove it should remove it from the right and put it back into the left) from diggin through the help docs in an attempt to RTFM i know the list is broken apart by |'s however was hoping there might be some way to feed it an array cause all i can see to do at this point is to use a regex to rebuild both tables accordingly when either button is pushed... X( not a regex fan hoping for a simpler way... maybe build an array for each and push / pop elements into the array before updating the GUI.. (sry know more perl verbage than autoit)? Don't let that status fool you, I am no advanced memeber! Link to comment Share on other sites More sharing options...
MuffettsMan Posted May 5, 2006 Author Share Posted May 5, 2006 WHOOT found _ArrayToString heheh looks like i can avoid regex once again Don't let that status fool you, I am no advanced memeber! Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted May 5, 2006 Moderators Share Posted May 5, 2006 (edited) There are alot of options with _GUICtrlList....Item/etc in the Beta, I don't know them so I did this real quick, maybe someone can give you a better example of how it should be done:expandcollapse popup#include <GUIConstants.au3 ; == GUI generated with Koda ==); Dim $ItemList1 = "Item 1|Item 2|Item 3|Item 4", $ItemList2 = '' $Form5 = GUICreate("Form1", 405, 269, 227, 154) $List1 = GUICtrlCreateList("", 16, 32, 129, 227) GUICtrlSetData($List1, $ItemList1) $GUI_AddButton = GUICtrlCreateButton("Add >>", 152, 88, 97, 25, 0) GUICtrlSetState($GUI_AddButton,$GUI_FOCUS) $GUI_CloseButton = GUICtrlCreateButton("<< Remove", 152, 152, 97, 25, 0) $List2 = GUICtrlCreateList("", 256, 32, 129, 227) GUISetState(@SW_SHOW) While 1 $msg = GuiGetMsg() Select case $msg = $GUI_AddButton $ItemList2 &= GUICtrlRead($List1) & '|' $ItemList1 = _ChangeList($List1, $List2, $ItemList1, GUICtrlRead($List1)) Case $msg = $GUI_CloseButton $ItemList1 &= GUICtrlRead($List2) & '|' $ItemList2 = _ChangeList($List2, $List1, $ItemList2, GUICtrlRead($List2)) Case $msg = $GUI_EVENT_CLOSE ExitLoop Case Else ;;;;;;; EndSelect WEnd Func _ChangeList($i_FromCTRLID, $i_ToCTRLID, $s_ItemList, $s_ToAdd) Local $aSplit = StringSplit($s_ItemList, '|'), $s_HoldValue = '' For $iCount = 1 To UBound($aSplit) - 1 If $aSplit[$iCount] <> $s_ToAdd And $aSplit[$iCount] <> '' Then $s_HoldValue &= $aSplit[$iCount] & '|' EndIf Next GUICtrlSetData($i_FromCTRLID, '') GUICtrlSetData($i_FromCTRLID, $s_HoldValue) GUICtrlSetData($i_ToCTRLID, $s_ToAdd) Return $s_HoldValue EndFunc Edit: Had Array Sort, but didn't need it, it seemed. Edited May 5, 2006 by SmOke_N Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
MuffettsMan Posted May 5, 2006 Author Share Posted May 5, 2006 (edited) i was thinking of something like... expandcollapse popup#include <GUIConstants.au3> #include <Array.au3> ; == GUI generated with Koda ==); $Form5 = GUICreate("Form1", 405, 269, 227, 154) $List1 = GUICtrlCreateList("", 16, 32, 129, 227) ; GUICtrlSetData($List1,"Item 1|Item 2|Item 3|Item 4|Item 5|Item 6|Item 7|Item 8|Item 9|Item 10") $GUI_AddButton = GUICtrlCreateButton("Add >>", 152, 88, 97, 25, 0) GUICtrlSetState($GUI_AddButton,$GUI_FOCUS) $GUI_CloseButton = GUICtrlCreateButton("<< Remove", 152, 152, 97, 25, 0) $List2 = GUICtrlCreateList("", 256, 32, 129, 227) GUISetState(@SW_SHOW) Dim $List1Array[9] $List1Array[0] = "Item 1" $List1Array[1] = "Item 2" $List1Array[2] = "Item 3" $List1Array[3] = "Item 4" $List1Array[4] = "Item 5" $List1Array[5] = "Item 6" $List1Array[6] = "Item 7" $List1Array[7] = "Item 8" $List1Array[8] = "Item 9" Dim $List1String = _ArrayToString($List1Array,"|") GUICtrlSetData($List1,$List1String) While 1 $msg = GuiGetMsg() Select case $msg = $GUI_AddButton GUICtrlSetData($List2,GUICtrlRead($List1)) _ArraySort( $List1Array ); Going to Sort the Array where we can Search for the element to be removed $iKeyIndex = _ArrayBinarySearch ( $List1Array,GUICtrlRead($List1)); Hopefully the Index of the element in the array _ArrayDelete ( $List1Array, $iKeyIndex );remove it from the array Dim $List1String = _ArrayToString($List1Array,"|") MsgBox(0,"", "The Index Found is: " & $iKeyIndex & " The Array 2 String: " & $List1String) GUICtrlSetData($List1,"") GUICtrlSetData($List1,$List1String) Case Else Case $msg = $GUI_EVENT_CLOSE ExitLoop Case Else ;;;;;;; EndSelect WEnd dunno if thats the 'right' way to do it but at least a starting attempt now just to make it do both arrays.... Edited May 5, 2006 by zhenyalix Don't let that status fool you, I am no advanced memeber! Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted May 5, 2006 Moderators Share Posted May 5, 2006 I think my example may be a tad easier Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
MuffettsMan Posted May 5, 2006 Author Share Posted May 5, 2006 (edited) I think my example may be a tad easier lol i must have some warped mind.... ((well that and your version is giving me errors maybe because i am running AutoIt V. 3.1.1.0? - scared of the word beta)) ok this is actually working all short of two parts............ expandcollapse popup#include <GUIConstants.au3> #include <Array.au3> ; == GUI generated with Koda ==); $Form5 = GUICreate("Form1", 405, 269, 227, 154) $List1 = GUICtrlCreateList("", 16, 32, 129, 227) ; GUICtrlSetData($List1,"Item 1|Item 2|Item 3|Item 4|Item 5|Item 6|Item 7|Item 8|Item 9|Item 10") $GUI_AddButton = GUICtrlCreateButton("Add >>", 152, 88, 97, 25, 0) GUICtrlSetState($GUI_AddButton,$GUI_FOCUS) $List2 = GUICtrlCreateList("", 256, 32, 129, 227) $GUI_RemoveButton = GUICtrlCreateButton("<< Remove", 152, 152, 97, 25, 0) GUICtrlSetState($GUI_RemoveButton,$GUI_FOCUS) GUISetState(@SW_SHOW) Dim $List2Array Dim $List1Array[9] $List1Array[0] = "Item 1" $List1Array[1] = "Item 2" $List1Array[2] = "Item 3" $List1Array[3] = "Item 4" $List1Array[4] = "Item 5" $List1Array[5] = "Item 6" $List1Array[6] = "Item 7" $List1Array[7] = "Item 8" $List1Array[8] = "Item 9" Dim $List1String = _ArrayToString($List1Array,"|") GUICtrlSetData($List1,$List1String) While 1 $msg = GuiGetMsg() Select case $msg = $GUI_AddButton If GUICtrlRead($List1) == "" Then MsgBox(0,"", "Please Select Something to be moved") Else GUICtrlSetData($List2,GUICtrlRead($List1) ) If IsArray($List2Array) Then _ArrayAdd ( $List2Array, GUICtrlRead($List1) ) Else Dim $List2Array $List2Array = _ArrayCreate(GUICtrlRead($List1) ) EndIf _ArraySort( $List1Array ); Going to Sort the Array where we can Search for the element to be removed Dim $iKeyIndex = _ArrayBinarySearch ( $List1Array,GUICtrlRead($List1)); Hopefully the Index of the element in the array _ArrayDelete ( $List1Array, $iKeyIndex );remove it from the array Dim $List1String = _ArrayToString($List1Array,"|") Dim $List2String = _ArrayToString($List2Array,"|") ;MsgBox(0,"", "The Index Found is: " & $iKeyIndex & " The L1Array 2 String: " & $List1String & " The L2Array 2 String: " & $List2String) GUICtrlSetData($List1,"") GUICtrlSetData($List1,$List1String) EndIf case $msg = $GUI_RemoveButton If GUICtrlRead($List2) == "" Then MsgBox(0,"", "Please Select Something to be moved") Else GUICtrlSetData($List1,GUICtrlRead($List2) ) ; MsgBox(0,"", "The Remove Button: " & GUICtrlRead($List2)) _ArrayAdd ( $List1Array, GUICtrlRead($List2) ) _ArraySort( $List2Array ); Going to Sort the Array where we can Search for the element to be removed Dim $iKeyIndex = _ArrayBinarySearch ( $List2Array,GUICtrlRead($List2)); Hopefully the Index of the element in the array _ArrayDelete ( $List2Array, $iKeyIndex );remove it from the array Dim $List2String = _ArrayToString($List2Array,"|") ; MsgBox(0,"", "The Index Found is: " & $iKeyIndex & " The Array 2 String: " & $List2String) GUICtrlSetData($List2,"") GUICtrlSetData($List2,$List2String) EndIf Case $msg = $GUI_EVENT_CLOSE ExitLoop ;;;;;;; EndSelect WEnd on a minor note when their is only one element left in the array the list box seems to drop it which i am sure i can figure out... my bigger problem is I don't want the second list sorted (building a sort of priority based on the order they are placed in) Edit* lol ok so that bug (prob logic error) is pretty bad move stuff back and forth long enough and you get all kinds of wild things and finally the most terrifying I pray there is some way i can pull the contents of the entire list out (in that unsorted order into an array if that isn't possible i am just gonna Edited May 5, 2006 by zhenyalix Don't let that status fool you, I am no advanced memeber! Link to comment Share on other sites More sharing options...
MuffettsMan Posted May 5, 2006 Author Share Posted May 5, 2006 I think my example may be a tad easier i get:list.au3 (16) : ==> Expected a "=" operator in assignment statement.: $ItemList2 &= GUICtrlRead($List1) & '|' $ItemList2 ^ ERROR+>AutoIT3.exe ended.rc:0>Exit code: 0 Time: 3.987 Don't let that status fool you, I am no advanced memeber! Link to comment Share on other sites More sharing options...
Simucal Posted May 5, 2006 Share Posted May 5, 2006 WHOOT found _ArrayToStringheheh looks like i can avoid regex once again Why the distaste for RegExp's? I honestly dont know how I lived without them before. To me, they are the best thing since sliced bread. AutoIt Scripts:Aimbot: Proof of Concept - PixelSearching Aimbot with several search/autoshoot/lock-on techniques.Sliding Toolbar - Add a nice Sliding Toolbar to your next script. Click the link to see an animation of it in action!FontInfo UDF - Get list of system fonts, or search to see if a particular font is installed.Get Extended Property UDF - Retrieve a files extended properties (e.g., video/image dimensions, file version, bitrate of song/video, etc) Link to comment Share on other sites More sharing options...
MuffettsMan Posted May 5, 2006 Author Share Posted May 5, 2006 Why the distaste for RegExp's? I honestly dont know how I lived without them before. To me, they are the best thing since sliced bread. cause of noobness ^([A-Z])*ness$ = headache ((one tends to despise that of which they still can't fully grasp)) Don't let that status fool you, I am no advanced memeber! Link to comment Share on other sites More sharing options...
MuffettsMan Posted May 5, 2006 Author Share Posted May 5, 2006 SmokN u were right your version was much simpler though dunno why my autoit doesn't like $var &= "new stuff" had to reformat it like: expandcollapse popup#include <GUIConstants.au3 ; == GUI generated with Koda ==); Dim $ItemList1 = "Item 1|Item 2|Item 3|Item 4|Item 5", $ItemList2 = '' $Form5 = GUICreate("Form1", 405, 269, 227, 154) $List1 = GUICtrlCreateList("", 16, 32, 129, 227) GUICtrlSetData($List1, $ItemList1) $GUI_AddButton = GUICtrlCreateButton("Add >>", 152, 88, 97, 25, 0) GUICtrlSetState($GUI_AddButton,$GUI_FOCUS) $GUI_CloseButton = GUICtrlCreateButton("<< Remove", 152, 152, 97, 25, 0) $List2 = GUICtrlCreateList("", 256, 32, 129, 227) GUISetState(@SW_SHOW) While 1 $msg = GuiGetMsg() Select case $msg = $GUI_AddButton If GUICtrlRead($List1) == "" Then MsgBox(0,"", "Please Select Something to be moved") Else $ItemList2 = $ItemList2 & GUICtrlRead($List1) & "|" $ItemList1 = _ChangeList($List1, $List2, $ItemList1, GUICtrlRead($List1)) EndIf Case $msg = $GUI_CloseButton If GUICtrlRead($List2) == "" Then MsgBox(0,"", "Please Select Something to be moved") Else $ItemList1 = $ItemList1 & GUICtrlRead($List2) & "|" $ItemList2 = _ChangeList($List2, $List1, $ItemList2, GUICtrlRead($List2)) EndIf Case $msg = $GUI_EVENT_CLOSE ExitLoop Case Else ;;;;;;; EndSelect WEnd Func _ChangeList($i_FromCTRLID, $i_ToCTRLID, $s_ItemList, $s_ToAdd) Local $aSplit = StringSplit($s_ItemList, '|'), $s_HoldValue = '' For $iCount = 1 To UBound($aSplit) - 1 ;MsgBox(0,"", "aSplit: " & $aSplit[$iCount]) If $aSplit[$iCount] <> $s_ToAdd And $aSplit[$iCount] <> '' Then $s_HoldValue = $s_HoldValue & $aSplit[$iCount] & '|' ;MsgBox(0,"", "aSplit MATCHED RULE: " & $aSplit[$iCount] & " holdValue: " & $s_HoldValue) EndIf Next GUICtrlSetData($i_FromCTRLID, '') GUICtrlSetData($i_FromCTRLID, $s_HoldValue) GUICtrlSetData($i_ToCTRLID, $s_ToAdd) Return $s_HoldValue EndFunc either way works nice now.. just odd even tried the latest beta 3.1.1.122 who knows Don't let that status fool you, I am no advanced memeber! Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted May 6, 2006 Moderators Share Posted May 6, 2006 SmokN u were right your version was much simpler though dunno why my autoit doesn't like $var &= "new stuff" had to reformat it like: expandcollapse popup#include <GUIConstants.au3 ; == GUI generated with Koda ==); Dim $ItemList1 = "Item 1|Item 2|Item 3|Item 4|Item 5", $ItemList2 = '' $Form5 = GUICreate("Form1", 405, 269, 227, 154) $List1 = GUICtrlCreateList("", 16, 32, 129, 227) GUICtrlSetData($List1, $ItemList1) $GUI_AddButton = GUICtrlCreateButton("Add >>", 152, 88, 97, 25, 0) GUICtrlSetState($GUI_AddButton,$GUI_FOCUS) $GUI_CloseButton = GUICtrlCreateButton("<< Remove", 152, 152, 97, 25, 0) $List2 = GUICtrlCreateList("", 256, 32, 129, 227) GUISetState(@SW_SHOW) While 1 $msg = GuiGetMsg() Select case $msg = $GUI_AddButton If GUICtrlRead($List1) == "" Then MsgBox(0,"", "Please Select Something to be moved") Else $ItemList2 = $ItemList2 & GUICtrlRead($List1) & "|" $ItemList1 = _ChangeList($List1, $List2, $ItemList1, GUICtrlRead($List1)) EndIf Case $msg = $GUI_CloseButton If GUICtrlRead($List2) == "" Then MsgBox(0,"", "Please Select Something to be moved") Else $ItemList1 = $ItemList1 & GUICtrlRead($List2) & "|" $ItemList2 = _ChangeList($List2, $List1, $ItemList2, GUICtrlRead($List2)) EndIf Case $msg = $GUI_EVENT_CLOSE ExitLoop Case Else ;;;;;;; EndSelect WEnd Func _ChangeList($i_FromCTRLID, $i_ToCTRLID, $s_ItemList, $s_ToAdd) Local $aSplit = StringSplit($s_ItemList, '|'), $s_HoldValue = '' For $iCount = 1 To UBound($aSplit) - 1 ;MsgBox(0,"", "aSplit: " & $aSplit[$iCount]) If $aSplit[$iCount] <> $s_ToAdd And $aSplit[$iCount] <> '' Then $s_HoldValue = $s_HoldValue & $aSplit[$iCount] & '|' ;MsgBox(0,"", "aSplit MATCHED RULE: " & $aSplit[$iCount] & " holdValue: " & $s_HoldValue) EndIf Next GUICtrlSetData($i_FromCTRLID, '') GUICtrlSetData($i_FromCTRLID, $s_HoldValue) GUICtrlSetData($i_ToCTRLID, $s_ToAdd) Return $s_HoldValue EndFunc either way works nice now.. just odd even tried the latest beta 3.1.1.122 who knows $var &= $var += $var -= Etc... Are all beta options... Sorry, I do it out of habbit now, and only do $var = $var & when I consciously think about it. Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. 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