Jump to content

how to append to an ini value?


Recommended Posts

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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

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