Daemante2018 Posted November 27, 2018 Share Posted November 27, 2018 (edited) I cannot get a simple INI file to print out to a list GUI. Can someone point me in the right direction? Whenever I try using the example below, nothing prints to the list. #include <GUIConstants.au3> #Include <File.au3> #Include <Array.au3> #Include <GUIConstants.au3> #Include <Constants.au3> $Form1 = GUICreate("AForm1", 633, 447, 193, 115) $List1 = GUICtrlCreateList("", 40, 40, 169, 357) GUISetState(@SW_SHOW) $FileList = IniReadSection("test.ini","Test") For $i In $FileList GUICtrlSetData($List1,$FileList) Next While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd [Test] Test=0 Test1=1 Test2=2 I am still trying to understand the array code so i wouldn't be surprised if I am doing it wrong. The point is only to have whats in the INI populated into the list; no need for counting. -------------------------------------------------------------------------------------------------------------------------------------- For anyone that finds this thread in search of similar answers, here was the solution: #include <Array.au3> #Include <File.au3> #Include <GUIConstants.au3> #include <GuiListBox.au3> #include <ListBoxConstants.au3> Local $hGui = GUICreate("AForm1", 633, 447, 193, 115) ;~ Sorted List GUICtrlCreateLabel("Sorted List", 40, 15, 170, 20) GUICtrlSetFont(-1, 14, 400) Local $idList1 = GUICtrlCreateList("", 40, 40, 170, 357) ;~ Unsorted List GUICtrlCreateLabel("Unsorted List", 220, 15, 170, 20) GUICtrlSetFont(-1, 14, 400) Local $idList2 = GUICtrlCreateList("", 220, 40, 169, 357, BitOR($LBS_NOTIFY, $WS_VSCROLL, $WS_BORDER)) GUICtrlSetFont(-1, 12, 400) GUICtrlSetColor(-1, 0xFF3300) GUISetState() Local $aFileList _FileReadToArray("Test.txt", $aFileList) For $i = 1 To $aFileList[0] _GUICtrlListBox_AddString($idList1,$aFileList[$i]) _GUICtrlListBox_AddString($idList2,$aFileList[$i]) Next While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd These were the lines responsible for producing the final desired outcome in my case: Local $aFileList _FileReadToArray("Test.txt", $aFileList) For $i = 1 To $aFileList[0] _GUICtrlListBox_AddString($idList1,$aFileList[$i]) _GUICtrlListBox_AddString($idList2,$aFileList[$i]) Next Edited November 29, 2018 by Daemante2018 Link to comment Share on other sites More sharing options...
BrewManNH Posted November 27, 2018 Share Posted November 27, 2018 INIReadSection returns a 2D array, so you can't do it that way, you'd have to loop through the array instead. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
Daemante2018 Posted November 27, 2018 Author Share Posted November 27, 2018 Is using an INI the "best" file type to accomplish this? Do any other file types allow for formatting to be read? Link to comment Share on other sites More sharing options...
careca Posted November 27, 2018 Share Posted November 27, 2018 I'd say is the easiest For $i=1 To $FileList[0][0] GUICtrlSetData($List1,$FileList[$i][1]) Next Daemante2018 1 Spoiler Renamer - Rename files and folders, remove portions of text from the filename etc. GPO Tool - Export/Import Group policy settings. MirrorDir - Synchronize/Backup/Mirror Folders BeatsPlayer - Music player. Params Tool - Right click an exe to see it's parameters or execute them. String Trigger - Triggers pasting text or applications or internet links on specific strings. Inconspicuous - Hide files in plain sight, not fully encrypted. Regedit Control - Registry browsing history, quickly jump into any saved key. Time4Shutdown - Write the time for shutdown in minutes. Power Profiles Tool - Set a profile as active, delete, duplicate, export and import. Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes. NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s. IUIAutomation - Topic with framework and examples Au3Record.exe Link to comment Share on other sites More sharing options...
Daemante2018 Posted November 27, 2018 Author Share Posted November 27, 2018 (edited) 5 minutes ago, careca said: I'd say is the easiest For $i=1 To $FileList[0][0] GUICtrlSetData($List1,$FileList[$i][1]) Next Yes so from that code it would appear I don't know how to use arrays. That worked. Using that example, the result was the "values" in the INI file. Should it not return the whole section? Edited November 27, 2018 by Daemante2018 Link to comment Share on other sites More sharing options...
Subz Posted November 27, 2018 Share Posted November 27, 2018 $FileList[$i][0] = first column or Ini Key $FileList[$i][1] = Second column or Ini Value Daemante2018 1 Link to comment Share on other sites More sharing options...
Daemante2018 Posted November 27, 2018 Author Share Posted November 27, 2018 Ahhh, thanks for the clarification @Subz Link to comment Share on other sites More sharing options...
Daemante2018 Posted November 27, 2018 Author Share Posted November 27, 2018 How could I change this example to use FileRead and a TXT file instead to have it read/format it line by line? This reads the information but it does not format line by line: #include <GUIConstants.au3> #Include <File.au3> #Include <Array.au3> #Include <GUIConstants.au3> #Include <Constants.au3> $Form1 = GUICreate("AForm1", 633, 447, 193, 115) $List1 = GUICtrlCreateList("", 40, 40, 169, 357) GUISetState(@SW_SHOW) $FileList = FileRead("test.txt") GUICtrlSetData($List1, $FileList) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd Link to comment Share on other sites More sharing options...
Subz Posted November 27, 2018 Share Posted November 27, 2018 No you would have to use something like _FileReadToArray example: #Include <File.au3> #Include <GUIConstants.au3> Local $hGui = GUICreate("AForm1", 633, 447, 193, 115) Local $idList = GUICtrlCreateList("", 40, 40, 169, 357) GUISetState() Local $aFileList _FileReadToArray("Test.txt", $aFileList) For $i = 1 To $aFileList[0] GUICtrlSetData($idList,$aFileList[$i]) Next While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd Daemante2018 1 Link to comment Share on other sites More sharing options...
Daemante2018 Posted November 27, 2018 Author Share Posted November 27, 2018 (edited) 2 minutes ago, Subz said: No you would have to use something like _FileReadToArray example: #Include <File.au3> #Include <GUIConstants.au3> Local $hGui = GUICreate("AForm1", 633, 447, 193, 115) Local $idList = GUICtrlCreateList("", 40, 40, 169, 357) GUISetState() Local $aFileList _FileReadToArray("Test.txt", $aFileList) For $i = 1 To $aFileList[0] GUICtrlSetData($idList,$aFileList[$i]) Next While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd I was actually playing with Filereadtoarray but I couldn't get it working; as opposed to _FileReadToArray. Your example worked as expected. Thank you. Edited November 27, 2018 by Daemante2018 Link to comment Share on other sites More sharing options...
Daemante2018 Posted November 27, 2018 Author Share Posted November 27, 2018 (edited) Can you just explain this one part of the array: For $i = 1 To $aFileList[0] <------- GUICtrlSetData($idList,$aFileList[$i]) Next What does the [0] represent? Array type = 1D? Also noticed that it will only read unique strings from the file and print those. Anything that is duplicate is left out. Is that behavior changeable? Is there anyway to have the file formatted, such as in RTF form, and have that formatting carry over to the Listbox? Edited November 27, 2018 by Daemante2018 Link to comment Share on other sites More sharing options...
Subz Posted November 27, 2018 Share Posted November 27, 2018 When you use _FileReadToArray without the optional parameters, the first item in the array or $aFileList[0] returns the last row number in the array, so For $i = 1 To <End of Array> see example below: _FileReadToArray without the $sDelimiter will return a 1D array otherwise it will display a 2D array in which case you would need to use For $i = 1 To $aFileList[0][0] With regards to RTF format, no I don't believe lists support that format. #include <Array.au3> #Include <File.au3> #Include <GUIConstants.au3> Local $hGui = GUICreate("AForm1", 633, 447, 193, 115) Local $idList = GUICtrlCreateList("", 40, 40, 169, 357) GUISetState() Local $aFileList _FileReadToArray("Test.txt", $aFileList) _ArrayDisplay($aFileList) For $i = 1 To $aFileList[0] GUICtrlSetData($idList,$aFileList[$i]) Next While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd Daemante2018 1 Link to comment Share on other sites More sharing options...
Daemante2018 Posted November 27, 2018 Author Share Posted November 27, 2018 15 hours ago, Subz said: When you use _FileReadToArray without the optional parameters, the first item in the array or $aFileList[0] returns the last row number in the array, so For $i = 1 To <End of Array> see example below: _FileReadToArray without the $sDelimiter will return a 1D array otherwise it will display a 2D array in which case you would need to use For $i = 1 To $aFileList[0][0] With regards to RTF format, no I don't believe lists support that format. #include <Array.au3> #Include <File.au3> #Include <GUIConstants.au3> Local $hGui = GUICreate("AForm1", 633, 447, 193, 115) Local $idList = GUICtrlCreateList("", 40, 40, 169, 357) GUISetState() Local $aFileList _FileReadToArray("Test.txt", $aFileList) _ArrayDisplay($aFileList) For $i = 1 To $aFileList[0] GUICtrlSetData($idList,$aFileList[$i]) Next While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd Thanks again for further explaining the concept @Subz! Link to comment Share on other sites More sharing options...
Daemante2018 Posted November 27, 2018 Author Share Posted November 27, 2018 How about the part about only returning unique strings? Anyway to have the function return all lines in the txt file regardless of what is on the line? Link to comment Share on other sites More sharing options...
careca Posted November 27, 2018 Share Posted November 27, 2018 _ArrayUnique Doesn't _FileReadToArray return all the lines for you? Spoiler Renamer - Rename files and folders, remove portions of text from the filename etc. GPO Tool - Export/Import Group policy settings. MirrorDir - Synchronize/Backup/Mirror Folders BeatsPlayer - Music player. Params Tool - Right click an exe to see it's parameters or execute them. String Trigger - Triggers pasting text or applications or internet links on specific strings. Inconspicuous - Hide files in plain sight, not fully encrypted. Regedit Control - Registry browsing history, quickly jump into any saved key. Time4Shutdown - Write the time for shutdown in minutes. Power Profiles Tool - Set a profile as active, delete, duplicate, export and import. Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes. NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s. IUIAutomation - Topic with framework and examples Au3Record.exe Link to comment Share on other sites More sharing options...
Daemante2018 Posted November 27, 2018 Author Share Posted November 27, 2018 (edited) If I use a txt file like below it only returns unique lines: test test1 test2 test3 test4 test test1 test2 test3 test4 test test1 test2 test3 test4 test test1 test2 test3 test4 test test1 test2 test3 _ArrayUnique is meant to remove the duplicates, from what I read in the help file, but I would like to leave the duplicates in. Edited November 27, 2018 by Daemante2018 Link to comment Share on other sites More sharing options...
Subz Posted November 27, 2018 Share Posted November 27, 2018 (edited) You mean something like: #include <Array.au3> #Include <File.au3> #Include <GUIConstants.au3> #include <GuiListBox.au3> #include <ListBoxConstants.au3> Local $hGui = GUICreate("AForm1", 633, 447, 193, 115) ;~ Sorted List GUICtrlCreateLabel("Sorted List", 40, 15, 170, 20) GUICtrlSetFont(-1, 14, 400) Local $idList1 = GUICtrlCreateList("", 40, 40, 170, 357) ;~ Unsorted List GUICtrlCreateLabel("Unsorted List", 220, 15, 170, 20) GUICtrlSetFont(-1, 14, 400) Local $idList2 = GUICtrlCreateList("", 220, 40, 169, 357, BitOR($LBS_NOTIFY, $WS_VSCROLL, $WS_BORDER)) GUICtrlSetFont(-1, 12, 400) GUICtrlSetColor(-1, 0xFF3300) GUISetState() Local $aFileList _FileReadToArray("Test.txt", $aFileList) For $i = 1 To $aFileList[0] _GUICtrlListBox_AddString($idList1,$aFileList[$i]) _GUICtrlListBox_AddString($idList2,$aFileList[$i]) Next While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd Edited November 27, 2018 by Subz Daemante2018 1 Link to comment Share on other sites More sharing options...
Daemante2018 Posted November 28, 2018 Author Share Posted November 28, 2018 (edited) Yes Subz that does the trick, thank you very much! Thank you @careca and @BrewManNH as well. Edited November 28, 2018 by Daemante2018 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