Jump to content

Recommended Posts

Posted

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.

Posted

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

Posted (edited)

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

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
×
×
  • Create New...