Sign in to follow this  
Followers 0
YoannMorl

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

16 posts in this topic

#1 ·  Posted (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 by YoannMorl

Share this post


Link to post
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 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

That's what i try do to but i don't understand how to create a loop for reading each file.

Edited by YoannMorl

Share this post


Link to post
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 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Ok, i've used iTranspose to have an array in the right direction.

I don't know how to do this loop.

Share this post


Link to post
Share on other sites

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._______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

 

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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._______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

 

Share this post


Link to post
Share on other sites

#9 ·  Posted (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 by YoannMorl

Share this post


Link to post
Share on other sites

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._______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

 

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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._______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

 

Share this post


Link to post
Share on other sites

#13 ·  Posted (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 by YoannMorl

Share this post


Link to post
Share on other sites

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._______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

 

Share this post


Link to post
Share on other sites

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 ^^

Share this post


Link to post
Share on other sites

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._______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

 

Share this post


Link to post
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
Sign in to follow this  
Followers 0