Hypertrophy Posted September 21, 2009 Share Posted September 21, 2009 (edited) I'm having major trouble reading and writing to an .ini file with multiple sections. What I'm trying to do is limit each section to 1000 keys per section. When I go to add new keys, it will correctly create a new section, for example [section2]. Where I'm running into trouble is if I want to append a value to one of my keys that already exists I am unsuccessful. It will just continue to create that value in a new key and not append it to the old key. What I am striving for is to write 1000 keys per section and create a new section when each section limit is reached, then if I want to write data to a key that already exists in 1 of the 3 sections that I may have then it will append to that keys value in the correct section. Help would be extremely appreciated. Here's what I have so far: For $x = 1 To $rdsectnames[0] $readinisection = IniReadSection($file, $rdsectnames[$x]) For $r = 1 To $readinisection[0][0] If $readinisection[$r][0] = $name Then ; if key already exists IniWrite ($file, $rdsectnames[$x], $name, IniRead($file, "Section" & $rdsectnames[0], $name, "") & "," & "Appended Value") ; append Else $sectionread = IniReadSection($file, "Section" & $rdsectnames[0]) ; read .ini section If IsArray($sectionread) Then ; if section contains keys/values If $sectionread[0][0] > 1000 Then ; if section contains more than 1000 keys IniWriteSection($file, "Section" & $rdsectnames[0] + 1, $name & "=" & "Value") ; make new section Else IniWrite($file, "Section" & $rdsectnames[0], $name, "Value") EndIf EndIf EndIf Next Next Edited September 21, 2009 by Hypertrophy Link to comment Share on other sites More sharing options...
99ojo Posted September 21, 2009 Share Posted September 21, 2009 I'm having major trouble reading and writing to an .ini file with multiple sections. What I'm trying to do is limit each section to 1000 keys per section. When I go to add new keys, it will correctly create a new section, for example [section2]. Where I'm running into trouble is if I want to append a value to one of my keys that already exists I am unsuccessful. It will just continue to create that value in a new key and not append it to the old key. What I am striving for is to write 1000 keys per section and create a new section when each section limit is reached, then if I want to write data to a key that already exists in 1 of the 3 sections that I may have then it will append to that keys value in the correct section. Help would be extremely appreciated. Here's what I have so far: For $x = 1 To $rdsectnames[0] $readinisection = IniReadSection($file, $rdsectnames[$x]) For $r = 1 To $readinisection[0][0] If $readinisection[$r][0] = $name Then ; if key already exists IniWrite ($file, $rdsectnames[$x], $name, IniRead($file, "Section" & $rdsectnames[0], $name, "") & "," & "Appended Value") ; append Else $sectionread = IniReadSection($file, "Section" & $rdsectnames[0]) ; read .ini section If IsArray($sectionread) Then ; if section contains keys/values If $sectionread[0][0] > 1000 Then ; if section contains more than 1000 keys IniWriteSection($file, "Section" & $rdsectnames[0] + 1, $name & "=" & "Value") ; make new section Else IniWrite($file, "Section" & $rdsectnames[0], $name, "Value") EndIf EndIf EndIf Next Next Hi, i think this line IniWrite ($file, $rdsectnames[$x], $name, IniRead($file, "Section" & $rdsectnames[0], $name, "") & "," & "Appended Value") ; append should be IniWrite ($file, $rdsectnames[$x], $name, IniRead($file, $rdsectnames[$x], $name, "") & "," & "Appended Value") ; append You also should post more code, because it's not clear, where $name is coming from ;-)) Stefan Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now