Sign in to follow this  
Followers 0
bendover

Reading multiple sections from ini-file to array

5 posts in this topic

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.

Share this post


Link to post
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 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

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)

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

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

AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)

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

Share this post


Link to post
Share on other sites

Thanks....works perfectly. Now I can search the values I want to use from array.

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