deve Posted October 3, 2015 Share Posted October 3, 2015 (edited) I am trying to write some entries to ini file this is my code :Case $Kaydet $LCOUNT = IniRead($sGuvercinINI, "Guvercin Kayıt", "", "") $answerOne = GUICtrlRead($Kunye) $answer2 = GUICtrlRead($Anne) $answer3 = GUICtrlRead($Baba) $answer4 = GUICtrlRead($Cinsi) $answer5 = GUICtrlRead($Renk) $answer6 = GUICtrlRead($Dogum) $answer7 = GUICtrlRead($Pic1) $answer8 = GUICtrlRead($Combo2) $answer9 = GUICtrlRead($Notlar) $LCOUNT=$LCOUNT+1 IniWrite($sGuvercinINI, $LCOUNT, "Künye", "") If IniRead($sGuvercinINI, "", "Künye", "") <> $answerOne Then IniWrite($sGuvercinINI, $LCOUNT, "Künye", $answerOne) IniWrite($sGuvercinINI, $LCOUNT, "Annesi", $answer2) IniWrite($sGuvercinINI, $LCOUNT, "Babası", $answer3) IniWrite($sGuvercinINI, $LCOUNT, "Cinsi", $answer4) IniWrite($sGuvercinINI, $LCOUNT, "Rengi", $answer5) IniWrite($sGuvercinINI, $LCOUNT, "Doğum", $answer6) IniWrite($sGuvercinINI, $LCOUNT, "Resmi", $answer7) IniWrite($sGuvercinINI, $LCOUNT, "Durumu", $answer8) IniWrite($sGuvercinINI, $LCOUNT, "Not", $answer9) Else MsgBox($MB_APPLMODAL, "", "Bu künye ile zaten başka bir kuş kayıtlı " & $answerOne) EndIf EndSwitchmy ini output is : [1] Künye=adsada Annesi= Babası= Cinsi= Rengi= Doğum= Resmi= Durumu=Durum Seç Not=Notlarso far everything is ok but when I enter new entries the script jusg updates the new entrie , I wont it to record us new entry like :[1] Künye=adsada Annesi= Babası= Cinsi= Rengi= Doğum= Resmi= Durumu=Durum Seç Not=Notlar [2] Künye=deve Annesi= Babası= Cinsi= Rengi= Doğum= Resmi= Durumu=Durum Seç Not=Notlar Edited October 3, 2015 by deve Link to comment Share on other sites More sharing options...
kylomas Posted October 3, 2015 Share Posted October 3, 2015 (edited) deve,If IniWrite finds a duplicate key in whatever section you are writing to, it will update that key, not add a new key. You might want to explain your task and/or post a reproducer for further assistance.kylomasP.S. A reproducer is "runnable" code.edit: dump $LCOUNT to the console or MSGBOX after the IniRead. I think you'll find it does not contain what you think it does. Edited October 3, 2015 by kylomas additional info Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
deve Posted October 3, 2015 Author Share Posted October 3, 2015 I am new to autoit this codes I toke from other topics they maybee not correct but what is the correct code to increase the added infos countlike this :[1] Künye=adsada Annesi= Babası= Cinsi= Rengi= Doğum= Resmi= Durumu=Durum Seç Not=Notlar [2] <<<< new entry gets number 2 if the key Künye is same value it must popup msg and say this value is allready recorded. Künye=deve Annesi= Babası= Cinsi= Rengi= Doğum= Resmi= Durumu=Durum Seç Not=Notlar Link to comment Share on other sites More sharing options...
mikell Posted October 4, 2015 Share Posted October 4, 2015 Have a careful look to all the Ini* funcs in the helpfileAssuming that the ini contains only sections [1], [2], ...[n] something like this should work :$sections = IniReadSectionNames($sGuvercinINI) ; number of sections in $sections[0] Local $value_exists = 0 For $i = 1 to $sections[0] ; loop through sections, looking for the value If IniRead($sGuvercinINI, $sections[$i], "Künye", "") = $answerOne Then $value_exists = $i Exitloop EndIf Next If $value_exists > 0 Then ; the value was found Msgbox(0,"", "this value is already recorded in section " & $sections[$value_exists]) ; ... Else ; value not found $newsection = $sections[0]+1 ; add a new section IniWrite($sGuvercinINI, $newsection, "...", "...") ; etc EndIf Link to comment Share on other sites More sharing options...
deve Posted October 4, 2015 Author Share Posted October 4, 2015 (edited) IHave a careful look to all the Ini* funcs in the helpfileAssuming that the ini contains only sections [1], [2], ...[n] something like this should work :$sections = IniReadSectionNames($sGuvercinINI) ; number of sections in $sections[0] Local $value_exists = 0 For $i = 1 to $sections[0] ; loop through sections, looking for the value If IniRead($sGuvercinINI, $sections[$i], "Künye", "") = $answerOne Then $value_exists = $i Exitloop EndIf Next If $value_exists > 0 Then ; the value was found Msgbox(0,"", "this value is already recorded in section " & $sections[$value_exists]) ; ... Else ; value not found $newsection = $sections[0]+1 ; add a new section IniWrite($sGuvercinINI, $newsection, "...", "...") ; etc EndIf When I use this I have this error : Subscript used on non-accessible variable.:in For $i = 1 to $sections[0] ; loop through sections, looking for the value mh code is like this : Case $Kaydet $answerOne = GUICtrlRead($Kunye) $answer2 = GUICtrlRead($Anne) $answer3 = GUICtrlRead($Baba) $answer4 = GUICtrlRead($Cinsi) $answer5 = GUICtrlRead($Renk) $answer6 = GUICtrlRead($Dogum) $answer7 = GUICtrlRead($hInput8) $answer8 = GUICtrlRead($Combo2) $answer9 = GUICtrlRead($Notlar) $sections = IniReadSectionNames($sGuvercinINI) ; number of sections in $sections[0] Local $value_exists = 0 For $i = 1 to $sections[0] ; loop through sections, looking for the value If IniRead($sGuvercinINI, $sections[$i], "Künye", "") = $answerOne Then $value_exists = $i Exitloop EndIf Next If $value_exists > 0 Then ; the value was found Msgbox(0,"", "this value is already recorded in section " & $sections[$value_exists]) ; ... Else ; value not found $newsection = $sections[0]+1 ; add a new section IniWrite($sGuvercinINI, $answerOne, "", "") IniWrite($sGuvercinINI, $answer2, "", "") IniWrite($sGuvercinINI, $answer3, "", "") IniWrite($sGuvercinINI, $answer4, "", "") IniWrite($sGuvercinINI, $answer5, "", "") IniWrite($sGuvercinINI, $answer6, "", "") IniWrite($sGuvercinINI, $answer7, "", "") IniWrite($sGuvercinINI, $answer8, "", "") IniWrite($sGuvercinINI, $answer9, "", "") ; etc EndIf Edited October 4, 2015 by deve Link to comment Share on other sites More sharing options...
Valuater Posted October 4, 2015 Share Posted October 4, 2015 Just a quick look...try $i = 1 to $sections[0] -18) deve 1 Link to comment Share on other sites More sharing options...
mikell Posted October 4, 2015 Share Posted October 4, 2015 (edited) Hmmm either the $sGuvercinINI var is not correctly defined, or the ini file is empty (no section inside)$sections = IniReadSectionNames($sGuvercinINI) ; number of sections in $sections[0] If @error Then ; ini file is empty $newsection = 1 ; add the first section IniWrite($sGuvercinINI, $newsection, "...", "...") ; etc Else Local $value_exists = 0 For $i = 1 to $sections[0] ; loop through sections, looking for the value If IniRead($sGuvercinINI, $sections[$i], "Künye", "") = $answerOne Then $value_exists = $i Exitloop EndIf Next If $value_exists > 0 Then ; the value was found Msgbox(0,"", "this value is already recorded in section " & $sections[$value_exists]) ; ... Else ; value not found $newsection = $sections[0]+1 ; add a new section IniWrite($sGuvercinINI, $newsection, "...", "...") ; etc EndIf EndIfBTW the IniWrite should be written like thisIniWrite($sGuvercinINI, $newsection, "Künye", $answerOne) ; etc Edited October 4, 2015 by mikell Link to comment Share on other sites More sharing options...
deve Posted October 4, 2015 Author Share Posted October 4, 2015 (edited) Just a quick look...try $i = 1 to $sections[0] -18)that worked thanks , many thanks mikellnow I need to read just 4 of the keys in ListView another question little problem when the ini file is empty it give me the same erorr :( Edited October 4, 2015 by deve Link to comment Share on other sites More sharing options...
mikell Posted October 4, 2015 Share Posted October 4, 2015 Did you try the code from post #7 ? Link to comment Share on other sites More sharing options...
deve Posted October 4, 2015 Author Share Posted October 4, 2015 (edited) Did you try the code from post #7 ?the first record comes out in ini like this allways : [1]...=... second record with the keys and values correct and why is my save button not correctly working I have to click on it sometimes 5 times to get it work? $sections = IniReadSectionNames($sGuvercinINI) ; number of sections in $sections[0] If @error Then ; ini file is empty $newsection = 1 ; add the first section IniWrite($sGuvercinINI, $newsection, "...", "...") ; etc Else Local $value_exists = 0 For $i = 1 to $sections[0] ; loop through sections, looking for the value If IniRead($sGuvercinINI, $sections[$i], "Künye", "") = $answerOne Then $value_exists = $i Exitloop EndIf Next If $value_exists > 0 Then ; the value was found Msgbox(0,"", "this value is already recorded in section " & $sections[$value_exists]) ; ... Else ; value not found $newsection = $sections[0]+1 ; add a new section ; IniWrite($sGuvercinINI, $newsection, "", "") IniWrite($sGuvercinINI, $newsection, "Künye", $answerOne) IniWrite($sGuvercinINI, $newsection, "Anne", $answer2) IniWrite($sGuvercinINI, $newsection, "Baba", $answer3) IniWrite($sGuvercinINI, $newsection, "Cinsi", $answer4) IniWrite($sGuvercinINI, $newsection, "Renk", $answer5) IniWrite($sGuvercinINI, $newsection, "Doğum", $answer6) IniWrite($sGuvercinINI, $newsection, "Resmi", $answer7) IniWrite($sGuvercinINI, $newsection, "Durumu", $answer8) IniWrite($sGuvercinINI, $newsection, "Notlar", $answer9) ; etc EndIf EndIf Edited October 4, 2015 by deve Link to comment Share on other sites More sharing options...
mikell Posted October 5, 2015 Share Posted October 5, 2015 the first record comes out in ini like this allways : [1]...=... If @error Then ; ini file is empty $newsection = 1 ; add the first section ( section [1] ) IniWrite($sGuvercinINI, $newsection, "...", "...") ; <<<<<<<<<<<<<<<<<<<< ; Obviously this was just a sample line and you must put instead the whole bunch of IniWrite ; etc Else ....Never heard of a save button. This is new ? deve 1 Link to comment Share on other sites More sharing options...
rudi Posted October 5, 2015 Share Posted October 5, 2015 Hi.I do such things as follows:write to the ini what's needetuse inireadsection to get all section namesread each section's content, sort it, write back to the ini the "sorting result"expandcollapse popup#include <array.au3> DirCreate("C:\temp") $INI="C:\temp\my.ini" Dim $aData[5][2]=[[4], _ ["Zappa","value1"], _ ["Planet","Earth"], _ ["The Answer","42"], _ ["Book","THHGTTG:DP"]] $Sect="1" for $i = 1 to $aData[0][0] IniWrite($INI,$Sect,$aData[$i][0],$aData[$i][1]) Next $Sect="2" for $i = $aData[0][0] to 1 Step -1 ;reverse initial order IniWrite($INI,$Sect,$aData[$i][0],$aData[$i][1]) Next $aSections=IniReadSectionNames($INI) if IsArray($aSections) Then MsgBox(0,"OK", "INI " & $INI & " has sections") for $s=1 to $aSections[0] $aContent=IniReadSection($INI,$aSections[$s]) _ArrayDisplay($aContent,$aSections[$s] & ": found order") _ArraySort($aContent) _ArrayDisplay($aContent,$aSections[$s] & ": Sorted (Collumn 1)") IniWriteSection($INI,$aSections[$s],$aContent) Next Else MsgBox(48,"ERR","INI " & $ini & " doesn't exist or has no sections.") EndIf Run ("notepad " & $ini)Regards, Rudi. Earth is flat, pigs can fly, and Nuclear Power is SAFE! Link to comment Share on other sites More sharing options...
deve Posted October 5, 2015 Author Share Posted October 5, 2015 If @error Then ; ini file is empty $newsection = 1 ; add the first section ( section [1] ) IniWrite($sGuvercinINI, $newsection, "...", "...") ; <<<<<<<<<<<<<<<<<<<< ; Obviously this was just a sample line and you must put instead the whole bunch of IniWrite ; etc Else ....Never heard of a save button. This is new ?this is final code I have and it works now :expandcollapse popupCase $Kaydet $answerOne = GUICtrlRead($Kunye) $answer2 = GUICtrlRead($Anne) $answer3 = GUICtrlRead($Baba) $answer4 = GUICtrlRead($Cinsi) $answer5 = GUICtrlRead($Renk) $answer6 = GUICtrlRead($Dogum) $answer7 = GUICtrlRead($hInput8) $answer8 = GUICtrlRead($Combo2) $answer9 = GUICtrlRead($Notlar) $sections = IniReadSectionNames($sGuvercinINI) ; number of sections in $sections[0] If @error Then ; ini file is empty $newsection = 1 ; add the first section ( section [1] ) IniWrite($sGuvercinINI, $newsection, "Künye", $answerOne) IniWrite($sGuvercinINI, $newsection, "Anne", $answer2) IniWrite($sGuvercinINI, $newsection, "Baba", $answer3) IniWrite($sGuvercinINI, $newsection, "Cinsi", $answer4) IniWrite($sGuvercinINI, $newsection, "Renk", $answer5) IniWrite($sGuvercinINI, $newsection, "Doğum", $answer6) IniWrite($sGuvercinINI, $newsection, "Resmi", $answer7) IniWrite($sGuvercinINI, $newsection, "Durumu", $answer8) IniWrite($sGuvercinINI, $newsection, "Notlar", $answer9) ; Obviously this was just a sample line and you must put instead the whole bunch of IniWrite ; etc Else Local $value_exists = 0 For $i = 1 to $sections[0] ; loop through sections, looking for the value If IniRead($sGuvercinINI, $sections[$i], "Künye", "") = $answerOne Then $value_exists = $i Exitloop EndIf Next If $value_exists > 0 Then ; the value was found Msgbox(0,"", "this value is already recorded in section " & $sections[$value_exists]) Else $newsection = $sections[0]+1 ; add a new section IniWrite($sGuvercinINI, $newsection, "Künye", $answerOne) IniWrite($sGuvercinINI, $newsection, "Anne", $answer2) IniWrite($sGuvercinINI, $newsection, "Baba", $answer3) IniWrite($sGuvercinINI, $newsection, "Cinsi", $answer4) IniWrite($sGuvercinINI, $newsection, "Renk", $answer5) IniWrite($sGuvercinINI, $newsection, "Doğum", $answer6) IniWrite($sGuvercinINI, $newsection, "Resmi", $answer7) IniWrite($sGuvercinINI, $newsection, "Durumu", $answer8) IniWrite($sGuvercinINI, $newsection, "Notlar", $answer9) EndIf EndIfsave button isCase $Kaydet << this is a button in GUI called $Kaydet when I click on this it runs the script but like I sayed before I need to click sometimes 5 times to get it work$Kaydet = GUICtrlCreateButton("Kaydet", 847, 612, 105, 25, $BS_DEFPUSHBUTTON) GUICtrlSetColor(-1, 0x000000) GUICtrlSetBkColor(-1, 0xFF8000) Link to comment Share on other sites More sharing options...
mikell Posted October 5, 2015 Share Posted October 5, 2015 There is probably elsewhere in the script something slowing down the main While loop deve 1 Link to comment Share on other sites More sharing options...
deve Posted October 5, 2015 Author Share Posted October 5, 2015 There is probably elsewhere in the script something slowing down the main While loopyes I guess also like this well how can I read this keys in listview now just 4 of them I need to read right after record to listview . I have managed to read just one section keys but the others I chouldnt , I done like this :Func _GetAccounts() Local $aAccounts = IniRead(@ScriptDir & '\guvercin.ini', "2", "Künye", "") Local $bAccounts = IniRead(@ScriptDir & '\guvercin.ini', "2", "Cinsi", "") Local $cAccounts = IniRead(@ScriptDir & '\guvercin.ini', "2", "Doğum", "") Local $dAccounts = IniRead(@ScriptDir & '\guvercin.ini', "2", "Durumu", "") If Not @error Then GUICtrlSetData($idItem1, $aAccounts) GUICtrlSetData($idItem1, "|" & $bAccounts) GUICtrlSetData($idItem1, "||" & $cAccounts) GUICtrlSetData($idItem1, "|||" & $dAccounts) EndIf EndFuncthis way I can read only in section 2 the values need to read all sections Link to comment Share on other sites More sharing options...
mikell Posted October 5, 2015 Share Posted October 5, 2015 GUICtrlSetData($idItem1, $aAccounts & "|" & $bAccounts & "|" & $cAccounts & "|" & $dAccounts)BTW you know what ? the help file is of great help deve 1 Link to comment Share on other sites More sharing options...
deve Posted October 5, 2015 Author Share Posted October 5, 2015 GUICtrlSetData($idItem1, $aAccounts & "|" & $bAccounts & "|" & $cAccounts & "|" & $dAccounts)BTW you know what ? the help file is of great help thanks for to make it shorter , between my english makes it hard to understand and find things in the help file , but many thanks to you now I am able to write to ini y project is half finish now but the read to listview is just for the Section 2 the other sections doesnt get read Local $aAccounts = IniRead(@ScriptDir & '\guvercin.ini', "2", "Künye", "") <<<< this 2 what do I need to change to make it loop to all sections and read them to listview Link to comment Share on other sites More sharing options...
deve Posted October 5, 2015 Author Share Posted October 5, 2015 (edited) this is my project GUIthis project when finished will be a great tool for all those who have pigenons Edited October 5, 2015 by deve Link to comment Share on other sites More sharing options...
mikell Posted October 5, 2015 Share Posted October 5, 2015 Man you understand of course that I can't write your whole script - especially because I must go to bed soon Here are clues for doing what you want, you will have to adapt and integrate this to the scriptGood luck Global $aItems ; declare array to store the IDs of the listview items Func _Fill_Listview() $sGuvercinINI = @ScriptDir & '\guvercin.ini' $sections = IniReadSectionNames($sGuvercinINI) ; get section names If not @error Then GuiCtrlSendMsg($listview, $LVM_DELETEALLITEMS, 0, 0) ; clean the listview Dim $aItems[$sections[0]] ; create and size the items array For $i = 1 to $sections[0] ; loop through sections Local $aAccounts = IniRead($sGuvercinINI, $sections[$i], "Künye", "") Local $bAccounts = IniRead($sGuvercinINI, $sections[$i], "Cinsi", "") Local $cAccounts = IniRead($sGuvercinINI, $sections[$i], "Dog(um", "") ; << typo here !! Local $dAccounts = IniRead($sGuvercinINI, $sections[$i], "Durumu", "") ; create listview items $aItems[$i-1] = GUICtrlCreateListViewItem($aAccounts & "|" & $bAccounts & "|" & $cAccounts & "|" & $dAccounts, $listview) GuiCtrlSetOnEvent($aItems[$i-1], "_display") Next EndIf EndFunc Func _display() For $i = 0 to UBound($aItems)-1 ; loop through the item IDs If @GUI_CtrlId = $aItems[$i] Then ; the item was clicked ; here put the instructions to display the image and infos for this item EndIf Next EndFunc deve 1 Link to comment Share on other sites More sharing options...
Teks Posted October 5, 2015 Share Posted October 5, 2015 As far as I see you're trying to develop a database-like app using INI files. Bad idea.Have you considered Visual Basic? if you want to avoid .Net, at least consider VBA+Excel+Forms for this task 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