BatMan22 Posted March 19, 2019 Share Posted March 19, 2019 So I'm really confused.. I used the script below to read a .txt file into a Array.. I display that array, and everything is perfect. I then assign the array values into a GuiCtrlList using a simple For loop.. and the data seems to auto-remove duplicates and auto sort itself..? I don't understand why.. I attached the file I was using as well. expandcollapse popup#include "UIAWrappers.au3" #include <Array.au3> #include <File.au3> #include <GUIConstantsEx.au3> #include <GUIListBox.au3> #include <WindowsConstants.au3> HotKeySet("+!q", "_quit") ; Quit Func _quit() Exit EndFunc ;==>_quit Global $arrayofloaded, $filename _FileReadToArray(@scriptdir & "\loadedfiles.txt", $arrayofloaded, 0) If @error Then MsgBox(0, 0, @error) Global $arrayfinal[Ubound($arrayofloaded)][2] ;~ _ArrayDisplay($arrayofloaded) For $i = 0 To UBound($arrayofloaded) - 1 ;~ ConsoleWrite("Starting with: " & $arrayofloaded[$i] & @CRLF) Local $sID = StringRegExp($arrayofloaded[$i], "\d\d\d\d\d\d\d\d.chw", 1) If @error Then MsgBox(0, 0, @error) $filename = $sID[0] $filename = StringRegExpReplace($filename, "\.chw", "") ; Remove the .cwh Local $realname = $arrayofloaded[$i] $realname = StringRegExpReplace($realname, "HPuv64.mtw", "") ; Remove the method name $realname = StringRegExpReplace($realname, "\d\d\d\d\d\d\d\d.chw", "") ; Remove the filename on IC $realname = StringRegExpReplace($realname, "<", "") ; Remove the < if file was open $realname = StringStripWS($realname, $STR_STRIPLEADING + $STR_STRIPTRAILING + $STR_STRIPSPACES) ConsoleWrite("Filename " & $filename & " corresponds to the real value: " & $realname & @CRLF) $arrayfinal[$i][0] = $filename $arrayfinal[$i][1] = $realname Next _ArrayDisplay($arrayfinal, "IC2 Loader","", 64) #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("IC2 Loader", 302, 487, 192, 124) $List1 = GUICtrlCreateList("", 0, 0, 60, 487) $List2 = GUICtrlCreateList("", 60, 0, 241, 487) For $i = 0 To UBound($arrayofloaded) - 1 GUICtrlSetData($List1, $arrayfinal[$i][0]) GUICtrlSetData($List2, $arrayfinal[$i][1]) Next GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd loadedfiles.txt Link to comment Share on other sites More sharing options...
Nine Posted March 19, 2019 Share Posted March 19, 2019 Because you need to separate your items with "|" in GUICtrlSetData (....) BatMan22 1 “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
FrancescoDiMuro Posted March 19, 2019 Share Posted March 19, 2019 @BatMan22 When you create the List, by default, it has the $LBS_SORT style set, so, the sorting of your list is an expected behaviour having that style. By the way, you are making way too many (and unnecessary) steps to have all the information you are retrieving from your file; one of many, you could read your file with the @TAB separator char. BatMan22 1 Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted March 19, 2019 Moderators Share Posted March 19, 2019 (edited) BatMan22, The default style for ListBoxes includes the $LBS_SORT style - hence sorting is default. if you want to have the ListBox unsorted, then you need to explicitly define the styles and omit the "sort" one: $List1 = GUICtrlCreateList("", 0, 0, 60, 387, BitOr($WS_BORDER, $WS_VSCROLL, $LBS_NOTIFY)) $List2 = GUICtrlCreateList("", 60, 0, 241, 387, BitOr($WS_BORDER, $WS_VSCROLL, $LBS_NOTIFY)) See the Setting Styles tutorial in the Wiki for more details. Using GUICtrlSetData when loading a ListBox sets any "double" values as the default - as explained in the Help file: Quote For Combo or List control : If the "data" corresponds to an already existing entry it is set as the default. You can always use _GUICtrlListBox_AddString to avoid this problem: ;GUICtrlSetData($List1, $arrayfinal[$i][0]) _GUICtrlListBox_AddString($List1, $arrayfinal[$i][0]) ;GUICtrlSetData($List2, $arrayfinal[$i][1]) _GUICtrlListBox_AddString($List2, $arrayfinal[$i][1]) Please ask if you have any further questions. M23 Edit: late, but more complete! Edited March 19, 2019 by Melba23 FrancescoDiMuro and BatMan22 2 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...
FrancescoDiMuro Posted March 19, 2019 Share Posted March 19, 2019 1 minute ago, Melba23 said: Edit: late, but more complete! Always appreciated. Thank you Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette Link to comment Share on other sites More sharing options...
BatMan22 Posted March 19, 2019 Author Share Posted March 19, 2019 Oops. Sorry and thank you guys! Didn't know that lists were sorted by default or that double values were set to default. Fixed code: #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("IC2 Loader", 302, 487, 192, 124) $List1 = GUICtrlCreateList("", 0, 0, 60, 487, BitOR($WS_BORDER, $WS_VSCROLL, $LBS_NOTIFY)) $List2 = GUICtrlCreateList("", 60, 0, 241, 487, BitOR($WS_BORDER, $WS_VSCROLL, $LBS_NOTIFY)) For $i = 0 To UBound($arrayofloaded) - 1 ;~ GUICtrlSetData($List1, $arrayfinal[$i][0]) ;~ GUICtrlSetData($List2, $arrayfinal[$i][1]) _GUICtrlListBox_AddString($List1, $arrayfinal[$i][0]) _GUICtrlListBox_AddString($List2, $arrayfinal[$i][1]) Next GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### Link to comment Share on other sites More sharing options...
Nine Posted March 19, 2019 Share Posted March 19, 2019 if you don't want to loop, you could use : GUICtrlSetData ($List1, _ArrayToString ($arrayfinal,"",Default,Default,"|",0,0)) GUICtrlSetData ($List2, _ArrayToString ($arrayfinal,"",Default,Default,"|",1,1)) Doesn't change much, but it is kind of cool using it like that BatMan22 1 “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
BatMan22 Posted March 19, 2019 Author Share Posted March 19, 2019 You know @Nine, if someone were to go through my programming and were to optimize everything and use 'smarter' coding, I bet you my programs would reduce by like ~85% as far as number of lines. I'm 35 and learning to program and wish I had started a long long time ago lol. That being said, thanks, I know something new now Link to comment Share on other sites More sharing options...
Nine Posted March 19, 2019 Share Posted March 19, 2019 1 minute ago, BatMan22 said: You know @Nine, if someone were to go through my programming and were to optimize everything and use 'smarter' coding, I bet you my programs would reduce by like ~85% as far as number of lines. I'm 35 and learning to program and wish I had started a long long time ago lol. That being said, thanks, I know something new now I know you'll go far in programming, you are the BatMan after all FrancescoDiMuro and BatMan22 2 “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy 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