Sign in to follow this  
Followers 0
Hypertrophy

how to append to an ini value?

9 posts in this topic

how do I append to an ini value that already exists in an inifile.

f.e:

[Section1]
Key=value1 <<< append to this with comma

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Read the value to a string, append another string to that, then write the value :)

Edited by Inverted

Share this post


Link to post
Share on other sites

IniWrite ("c:\test.ini", "section1", "key", IniRead ("c:\test.ini", "section1", "key") & ",")

that work?

MDiesel

Share this post


Link to post
Share on other sites

Thank you mdiesel! That works perfect.

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

is this the correct way to check if a string exists as a key?

$string = "abc"
$keycheck = IniReadSection($inifile, "section1")    ; reads the section for all key/value pairs
If @error Then 
    MsgBox(0, "","Error")
Else
        For $i = 1 To $keycheck[0][0]
               If $keycheck[$i][0] = $string Then
                      msgbox(0,"","string 'abc' exists as key in ini file")
               Else
                      msgbox(0,"","string 'abc' not found..")
               EndIf
        Next
EndIf
Edited by Hypertrophy

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Hey,

try this, so you don't need a loop :)

$sKey = "abc"
If IniRead("file.ini", "section", $sKey, "#ITDOESNOTEXIST#") <> "#ITDOESNOTEXIST#" Then
    ConsoleWrite("Key '" & $sKey & "' exists." & @CRLF)
Else
    ConsoleWrite("Key '" & $sKey & "' does not exist." & @CRLF)
EndIf
Edited by Robjong

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

Wouldn't a loop be necessary though I there were 10 keys or 20 and you really had no idea of what they might be?

Edited by Hypertrophy

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

Wouldn't a loop be necessary though I there were 10 keys or 20 and you really had no idea of what they might be?

If you want to match partial kays or values you would need a loop.

Not if you only need an exact match of the key, the last param of IniRead is the default return value for when the key does not exist, so when that value (in this case #ITDOESNOTEXIST#) is returned the key does not exist.

Read the help file for IniRead :)

Edited by Robjong

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

Ok. I think im starting to understand. so could i just do like this instead of having "#ITDOESNOTEXIST#"

$sKey = "abc"
If IniRead("file.ini", "section", $sKey, "") <> "" Then
    ConsoleWrite("Key '" & $sKey & "' exists." & @CRLF)
Else
    ConsoleWrite("Key '" & $sKey & "' does not exist." & @CRLF)
EndIf

Would that still work?

Edit: Nevermind, added ExitLoop and my code works perfect. Thanks for the help though.

Edited by Hypertrophy

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