Sign in to follow this  
Followers 0
maxcronjob

Read from an array in an .ini file?

9 posts in this topic

Is this do-able?

Has anyone ever created an array from a list in an .ini file and pulled it into a loop in their script?

I have a list of strings (123456, ABCDEF, KB890046....) and a huge Case statement that checks for each one of these strings.

I'd like to dump all of these strings into an .ini file - somehow - and reduce the Case statement to a single Case that checks for values in the array.

I'm not sure how to go about this.

Thanks,

max

Share this post


Link to post
Share on other sites



one of my favorites

$days = StringSplit("Sun,Mon,Tue,Wed,Thu,Fri,Sat", ",")
;$days[1] contains "Sun" ... $days[7] contains "Sat"

For $x = 1 to $days[0]
    MsgBox(0," Results", $days[$x])
Next

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites

That's all good, but how does one read values from an .ini file into an array?

from .ini:

[section]

string1

string2

string3

....

from code:

$ini_test = IniReadSection(@ScriptDir & "\my.ini", "Section")

$ini_array = StringSplit($ini_test, @CRLF, 1)

For $i = 1 To $ini_array[0]

If $ini_array[$i] = $MyTest Then

(write output...)

Else

(write other output...)

EndIf

Next

Thanks,

max

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

I'm not picking at each word in your post - just explaining what I saw/thought:

...ever created an array from a list in an .ini file

Okay, so the data is already in an INI file and (s)he wants to put it into an array.

...I'd like to dump all of these strings into an .ini file...

Oh, so the data is not already in an INI file... perhaps what I posted in another thread might help. (A thread that does not deal with INI files.)

Maybe the data needs to be in that INI format or maybe it is already there. I've never worked with INI files, I'll leave the answer to those that have. Sorry for the detour... if any.

Edited by herewasplato

[size="1"][font="Arial"].[u].[/u][/font][/size]

Share this post


Link to post
Share on other sites

If you make your ini file look like this ..

[section_1]123456=1

ABCDEF=1

KB890046=1

.. then you can use this kind of test on it ..

$sINI = "D:\Temp\hits.ini"
    $sTest = InputBox( $sINI, "What to test for?" )

    If INIRead( $sINI, "section_1", $sTest, 0 ) = 1 then
        Msgbox( 0, "", "Hit!" )
    else
        Msgbox( 0, "", "Missed" )
    EndIf

HTH

B)

Share this post


Link to post
Share on other sites

Hello

An INI file is just a file. So if you want to read it and assignt this file to an array, you can use te UDF _FileReadToArray

#include <file.au3>

Dim $Tokens ; The Array ....

If Not _FileReadToArray("C:\windows\MySoft.ini",$Tokens) Then

....

This will create an array with a record for each line readen from the ini.

HTH,

Francis

Share this post


Link to post
Share on other sites

If you make your ini file look like this ..

.. then you can use this kind of test on it ..

$sINI = "D:\Temp\hits.ini"
    $sTest = InputBox( $sINI, "What to test for?" )

    If INIRead( $sINI, "section_1", $sTest, 0 ) = 1 then
        Msgbox( 0, "", "Hit!" )
    else
        Msgbox( 0, "", "Missed" )
    EndIf

HTH

:lmao:

Outstanding reply!!! I didn't think it could be that simple!

Thanks!!!!

max

Share this post


Link to post
Share on other sites

Outstanding reply!!! I didn't think it could be that simple!

Thanks!!!!

max

The simplest way is already available in AutoIT, IniReadSection() it reads the section and puts it in a 2d array. If you have a look at my client from this post http://www.autoitscript.com/forum/index.php?showtopic=20525 I have a set of windows I want to check for all are stored in an ini section. I then use a for loop and check for each window.

You may want to down load the RemoteClient.au3 the winClient.ini and the readme file to understand what it does

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