Jump to content

Reading multiple sections from ini-file to array


 Share

Recommended Posts

I have dialogue that reads city selection from ini-file. There are three sections in ini-file. Example:

[CITY]

City1=Chicago

City2=Stockholm

City3=New York

[PREFIX]

Prefix1=CHI

Prefix2=STC

Prefix3=NYC

[OU]

Ou1="LDAP://dc1.corp.domain.com/OU=Chicago,OU=Computers,DC=corp,DC=domain,DC=com

Ou2="LDAP://dc1.corp.domain.com/OU=Stockholm,OU=Computers,DC=corp,DC=domain,DC=com

Ou3="LDAP://dc1.corp.domain.com/OU=New York,OU=Computers,DC=corp,DC=domain,DC=com

All sections have connection to each others (City1=Prefix1=Ou1 etc). I read city section to array but the question is: how to read all sections to multidimensional array and keep the connection described earlier? I'm not very familiar with multidimensional arrays.

Thanks in advance.

Link to comment
Share on other sites

Welcome to AutoIt and the forum!

If the entries in every section always have the same order (means: The 2nd entry in [CITY] is City2 and the 2nd entry in [PREFIX] is Prefix2 etc.) then you could usse INIRead to read the sections into 3 arrays and access the content by index.

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

Because you're not very familiar with multidimensional arrays...  :)

#include <Array.au3>

$ini = @ScriptDir & "\ini.ini"

$city = IniReadSection($ini, "CITY")
$prefix = IniReadSection($ini, "prefix")
$ou = IniReadSection($ini, "ou")

$nb = $city[0][0]
Local $res[$nb+1][3]
$res[0][0] = $nb
For $i = 1 to $nb
   $res[$i][0] = $city[$i][1]
   $res[$i][1] = $prefix[$i][1]
   $res[$i][2] = $ou[$i][1]
Next
_ArrayDisplay($res)
Link to comment
Share on other sites

Or a simpler approach, using some of the same calls, if you only want one city at a time. No array.
 

Global $cities, $city, $details, $inifle, $num, $ou, $prefix, $total

$inifle = @ScriptDir & "\Citydetail.ini"

$cities = IniReadSection($inifle, "CITY")

$total = $cities[0][0]

For $num = 1 To $total
    $city = IniRead($inifle, "CITY", "City" & $num, "")
    $prefix = IniRead($inifle, "PREFIX", "Prefix" & $num, "")
    $ou = IniRead($inifle, "OU", "Ou" & $num, "")
    $details = "City = " & $city & @LF & "Prefix = " & $prefix & @LF & "Ou = " & $ou
    MsgBox(0, "City Details", $details)
Next
Edited by TheSaint

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

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