Jump to content

Help With Ini File


Recommended Posts

Hey guys, I am not working on any script right now. I was just reading up on working with ini files, and I came across a problem. What I am trying

to do is make a script that makes the following ini file:

(it's just for educational purposes)

[section 1]

Value 1=1

Value 2=2

Value 3=3

[section 2]

Value 1=1

Value 2=2

Value 3=3

[section 3]

Value 1=1

Value 2=2

Value 3=3

Here is the code that I made:

;Ini file reader


$ini = @DesktopDir & "\test.ini"
$key=1
For $section = 1 To 3 Step 1
    IniWriteSection($ini, "Section " & $section, "Value " & $key)
    For $key = 1 To 3 Step 1
        IniWrite($ini, "Section " & $section, "Value " & $key, $key)
    Next
Next

However, the file comes out different than it should. This is how the file comes out as:

[section 1]

Value 1=1

Value 2=2

Value 3=3

Value 1 <----

value <----

[section 2]

Value 1=1

Value 2=2

Value 3=3

Value 4 <----

[section 3]

Value 1=1

Value 2=2

Value 3=3

Value 4 <---- Where are all these things coming from?

Both my for loops should end at 3, where is the 4 coming from?

The places I marked are different from what I expected it to be.

I don't want to see the right code, I just want someone to show me what I am doing wrong.

Any help would be appreciated,

Thanks a lot.

Link to comment
Share on other sites

Beginner321,

Try removing step 1 from the For Next statement in your script.

jfcby

Determined -- Devoted -- Delivered Make your mind up -- to seriously apply yourself -- accomplishing the desired results. **** A soft answer turneth away wrath: but grievous words stir up anger. Proverbs 15:1 KJB ****

Link to comment
Share on other sites

Use either IniWriteSection or IniWrite, not both. When you do IniWriteSection you write the whole section in one shot. See the help file. Also you are concatenating an integer onto a string. To concatenate the string value of $section you should use $stringVar = "string " & String($Section).

If you use the sample code from the help then display arrays using _ArrayDisplay() you'll find it easier to see what's going on. Good luck with it. :blink:

Also in For loops increment by one is the default. The "Step" is not needed.

Edited by MilesAhead
Link to comment
Share on other sites

This works.

$ini = @ScriptDir & "\test.ini"
$key=1
For $section = 1 To 3 Step 1
    IniWriteSection($ini, "Section " & $section, "")
    For $key = 1 To 3 Step 1
        IniWrite($ini, "Section " & $section, "Value " & $key, $key)
    Next
Next

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

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