Sign in to follow this  
Followers 0
ARozanski

.ini ReWrite

6 posts in this topic

I have built an .ini with a certain amount of variables under a certain Section. The order of the keys in the section is essential to the program...is there any way i can change the value of the keys without having to delete the key and adding a new one which will go to the end of the section??

Share this post


Link to post
Share on other sites



IniWrite writes a NEW KEY with a NEW VALUE - which is ok - but it puts it at the END of the SECTION...like i said - the order of the keys in the section is essential for the program - ie. i cant start moving keys to the end...

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

well if you used it with an existing key with existing value & existing section

it will just replace it

example :

you have this ini

[Section]
1=1
2=2
3=3

use this code

IniWrite("New Text document.txt","Section","2","Changed")

and it will change the calue of key 2 to Changed with the same order

Edited by komalo

[font="Palatino Linotype"][size="3"]AutoIt Script Examples :[/size][/font][font="Palatino Linotype"][size="3"]_CaptureBehindWindowGlass CMD for Windows Vista/Seven[/size][/font][left][/left][font="Palatino Linotype"][size="3"]Non AutoIt Script programs : Border Skin - Aero Glass On XP[/size][/font]

Share this post


Link to post
Share on other sites

ARozanski

Try this:

$sResult = _IniWriteEx(@ScriptDir & "\test.ini", "Section", "NewValue", "NewKey", 2)

Func _IniWriteEx($sPath, $sSection, $sVal, $sKey, $sPos)
    Local $aSection, $iRead, $i
    $aSection = IniReadSection($sPath, $sSection)
    
    For $i = 1 To $aSection[0][0]
        If $i = $sPos Then $iRead &= $sVal & "=" & $sKey & @LF
        $iRead &= $aSection[$i][0] & "=" & $aSection[$i][1] & @LF
    Next
    
    Return IniWriteSection($sPath, $sSection, $iRead)
EndFunc

:P

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