Jump to content

Changing values in INI file


Recommended Posts

When I create my INI file, how would I be able to search for "02=Cat" and change Cat to a specific kind like "02=Maine Coon Cat"? Being able to change whatever would be in section [02=]

#include <MsgBoxConstants.au3>
#include <Array.au3>

; -------- Create ini file -----------
FileWrite("Search.ini", _
        "[Search Animals]" & @CRLF & _
        "IGNORE_ERRORS=0" & @CRLF & _
        "01=Dog" & @CRLF & _
        "02=Cat" & @CRLF & _
        "03=Bird" & @CRLF & _
        "04=Fish")
Sleep(1000)
; ------ End of Create ini file ------

_read()

FileDelete("Search.ini") ; Tidy up


Func _read()
    Local Const $hostfile = "Search.ini"
    $var = IniReadSection($hostfile, "Search Animals")
    If @error Then
        MsgBox(4096, "Error", "Unable to read section.")
    Else
        For $number = 1 To $var[0][0]
            ; MsgBox(4096, "", "Key: " & $var[$i][0] & @CRLF & "Value: " & $var[$number][1])
            If $var[$number][1] == "Cat" Then
                MsgBox($MB_SYSTEMMODAL, "Search", "The " & $var[$number][1] & " was found at " & $var[$number][0], 5)
                ExitLoop ; Exits For - Next loop (stops) when search value, "Cat", is found?
            EndIf
        Next
    EndIf
    _ArrayDisplay($var, "Search Animals")
EndFunc   ;==>_read

 

Edited by aa2zz6
Added more info to description that might help explain
Link to post
Share on other sites

IniReadSectionNames will give you all sections of an ini file

IniReadSection will give you all keys of an ini section.

You just need to loop thru those 2 arrays and find the one you are looking for.

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
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...