YoannMorl Posted November 20, 2012 Share Posted November 20, 2012 (edited) Hi, I'm trying to display an Array with multiple ini file. Each ini file is the same but data change. XXX000001.ini [sECTION] KEY1=VAR1 KEY2=VAR2 ... XXX000002.ini [sECTION] KEY1=VAR1 KEY2=VAR2 ... I'd like to display an Array like that : KEY1 -- KEY2 -- ... VAR1 -- VAR2 -- ... <- from XXX000001.ini VAR1 -- VAR2 -- ...<- from XXX000002.ini ... I don't know how to to that. Could you help me please ? Too, i'd like to set data in a Combo Box with the name of each ini file (without .ini) for each file containing this line : ETAT=LIBRE Don't know how to do too. Regards. Edited November 21, 2012 by YoannMorl Link to comment Share on other sites More sharing options...
water Posted November 20, 2012 Share Posted November 20, 2012 Read each ini file to an array using IniReadSection. Then combine the arrays to a new array in the format you need. My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
YoannMorl Posted November 20, 2012 Author Share Posted November 20, 2012 (edited) That's what i try do to but i don't understand how to create a loop for reading each file. Edited November 20, 2012 by YoannMorl Link to comment Share on other sites More sharing options...
water Posted November 20, 2012 Share Posted November 20, 2012 To read the file no loop is needed. The function IniReadSection creates the array for you. Check the help file and you will see what I mean. You need a loop to process the array. My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
YoannMorl Posted November 20, 2012 Author Share Posted November 20, 2012 Ok, i've used iTranspose to have an array in the right direction. I don't know how to do this loop. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted November 20, 2012 Moderators Share Posted November 20, 2012 YoannMorl, Here is how I would get the ini data into an array: #include <Array.au3> #include <File.au3> ; List all the ini files $aIni_List = _FileListToArray(@ScriptDir, "XXX*.ini", 1) ; Check how many key=value pairs we will get $aIni_Content = IniReadSection($aIni_List[1], "SECTION") ; And create a suitably sized array to hold all the data Global $aResults[$aIni_List[0] + 1][$aIni_Content[0][0]] ; Set the title row For $i = 1 To $aIni_Content[0][0] $aResults[0][$i - 1] = $aIni_Content[$i][0] Next ; Now get the values from each file and put them into the array For $i = 1 To $aIni_List[0] $aIni_Content = IniReadSection($aIni_List[$i], "SECTION") For $j = 1 To $aIni_Content[0][0] $aResults[$i][$j - 1] = $aIni_Content[$j][1] Next Next ; And show the result _ArrayDisplay($aResults) And here is how I would list the ini files in a combo: #include <GUIConstantsEx.au3> #include <File.au3> ; List all the ini files $aIni_List = _FileListToArray(@ScriptDir, "XXX*.ini", 1) ; Create a string to fill the combo $sIni_List = "" ; Now add the ini files to the list - removing the .ini extension For $i = 1 To $aIni_List[0] $sIni_List &= "|" & StringTrimRight($aIni_List[$i], 4) Next $hGUI = GUICreate("Test", 500, 500) $cCombo = GUICtrlCreateCombo("", 10, 10, 200, 20) ; Add the data string GUICtrlSetData($cCombo, $sIni_List) GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd All clear? 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...
YoannMorl Posted November 20, 2012 Author Share Posted November 20, 2012 Wow, thanks Melba. I've tried the first script but i have this error Subscript used with non-Array variable.: Global $aResults[$aIni_List[0] + 1][$aIni_Content[0][0]] Global $aResults[$aIni_List[0] + 1][$aIni_Content^ ERROR Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted November 20, 2012 Moderators Share Posted November 20, 2012 YoannMorl, The error occurs because the array has no content - either no ini files were found or there was no [sECTION] found within it. My posted code had no errorchecking - so try adding some to make sure you get the arrays you think you should. The code certainly works for me with inis in the format you posted when they are in the same folder. 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...
YoannMorl Posted November 20, 2012 Author Share Posted November 20, 2012 (edited) I don't doubt about your script ^^ This what i've done : #include <Array.au3> #include <File.au3> ; List all the ini files $aIni_List = _FileListToArray(@ScriptDir & "DB", "GRE*.ini", 1) ; Check how many key=value pairs we will get $aIni_Content = IniReadSection($aIni_List[1], "INFOS") ; And create a suitably sized array to hold all the data Global $aResults[$aIni_List[0] + 1][$aIni_Content[0][0]] ; Set the title row For $i = 1 To $aIni_Content[0][0] $aResults[0][$i - 1] = $aIni_Content[$i][0] Next ; Now get the values from each file and put them into the array For $i = 1 To $aIni_List[0] $aIni_Content = IniReadSection($aIni_List[$i], "INFOS") For $j = 1 To $aIni_Content[0][0] $aResults[$i][$j - 1] = $aIni_Content[$j][1] Next Next ; And show the result _ArrayDisplay($aResults) And this is one of my ini file called : GRE014725.ini [iNFOS] GRE=GRE123456 TYPE=Portable MARQUE=Lenovo MODELE=Modèle1 SERIE=Série0001 ETAT=RESERVE SD=Input1 DU=2012/11/20 AU=2012/11/27 For the combo box i need to list only files that contains this : ETAT=LIBRE Edited November 20, 2012 by YoannMorl Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted November 20, 2012 Moderators Share Posted November 20, 2012 YoannMorl,As the ini file is not in the same folder as the script, you need to use the full path: IniReadSection(@ScriptDir & "DB" & $aIni_List[1], "INFOS")You need to do this in 2 places. 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...
YoannMorl Posted November 20, 2012 Author Share Posted November 20, 2012 Grrr ^^ If i think just about 2 minutes ^^ It works, thank you. For the combo box i need to list only files that contains this : ETAT=LIBRE Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted November 20, 2012 Moderators Share Posted November 20, 2012 YoannMorl, Glad you got it working. As to the second part - time for you to do some work. You have a list of the ini files - so look for the key in each one as you loop through and only add the name to the list if the value is correct. I will be here if you get stuck. 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...
YoannMorl Posted November 20, 2012 Author Share Posted November 20, 2012 (edited) Tried that but don't work : For $i = 1 To $aIni_List[0] If IniRead(@ScriptDir & "DB" & $aIni_List[0],"INFOS","ETAT","ERROR") = "LIBRE" Then $sIni_List &= "|" & StringTrimRight($aIni_List[$i], 4) EndIf Next or this : ; Now add the ini files to the list - removing the .ini extension For $i = 1 To $aIni_List[0] $libre = IniRead(@ScriptDir & "DB" & $aIni_List[0],"INFOS","ETAT","ERROR") If $libre = "LIBRE" Then $sIni_List &= "|" & StringTrimRight($aIni_List[$i], 4) EndIf Next Edited November 20, 2012 by YoannMorl Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted November 20, 2012 Moderators Share Posted November 20, 2012 YoannMorl, Nice to see someone else is also not having a good day: Can you spot the difference: ; Your script If IniRead(@ScriptDir & "DB" & $aIni_List[0],"INFOS","ETAT","ERROR") = "LIBRE" Then ; My script If IniRead(@ScriptDir & "DB" & $aIni_List[$i], "INFOS", "ETAT", "ERROR") = "LIBRE" Then All clear? 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...
YoannMorl Posted November 20, 2012 Author Share Posted November 20, 2012 Mouarf ^^ Working ^^ Sorry to wast your time ^^ I'm scripting since this morning, my eyes are not very good now ^^ Thanks for your help and to not give me the solution immediately. Good way to learn. Regards ^^ Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted November 20, 2012 Moderators Share Posted November 20, 2012 YoannMorl,Thanks for your help and to not give me the solution immediately. Good way to learn.Pleased you see that - and glad I could help. 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...
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