Jump to content

[R] Array with multiple ini file and combobox with key


 Share

Recommended Posts

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 by YoannMorl
Link to comment
Share on other sites

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 - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

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 - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

  • Moderators

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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • Moderators

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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

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 by YoannMorl
Link to comment
Share on other sites

  • Moderators

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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • Moderators

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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

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 by YoannMorl
Link to comment
Share on other sites

  • Moderators

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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • Moderators

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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...