misterDee Posted June 18, 2010 Share Posted June 18, 2010 Hi, Ive got a question about the command 'iniwrite', i cant figure it out i have the function 'fileselectfolder', if your choose a map then it must be writen in a ini-file, so far no problem.. But if i choose more then 1 map its overrollin' in the ini.. index of ini: [Test] files=c:\bla files=c:\bla2 files=c:\bla3 etc.. same for the function iniread to read it out.. how can i make a loop thats write the ini like in the example!? thanks! Greets MisterD! Link to comment Share on other sites More sharing options...
PsaltyDS Posted June 18, 2010 Share Posted June 18, 2010 The functions IniRead() and IniWrite() don't have indices for multiple instances of a key, so use IniReadSection() and IniWriteSection() instead and work with the arrays. Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
misterDee Posted June 18, 2010 Author Share Posted June 18, 2010 Thanks for your replay, can you give me a example? im not so good with array's! Link to comment Share on other sites More sharing options...
PsaltyDS Posted June 18, 2010 Share Posted June 18, 2010 There are examples in the help file under both of those functions. That really should be your first resource for help. P.S. This topic should be in General Help and Support. This forum is for questions specific to GUIs. Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
misterDee Posted June 18, 2010 Author Share Posted June 18, 2010 Ive been checkin' the help and forums.. something is not workin! thats why i post a help over here Link to comment Share on other sites More sharing options...
ajag Posted June 18, 2010 Share Posted June 18, 2010 Ive been checkin' the help and forums.. something is not workin! thats why i post a help over here Somthin's not working??? This is the example from the help of IniWriteSection. Look at it, run it, look at the result at your desktop and understand ; This is the INI file we will write to. It will be created on the Desktop. $sIni = @DesktopDir & "\AutoIt-Test.ini" ; Demonstrate creating a new section using a string as input. $sData = "Key1=Value1" & @LF & "Key2=Value2" & @LF & "Key3=Value3" IniWriteSection($sIni, "Section1", $sData) ; Demonstrate creating a new section using an array as input. $aData1 = IniReadSection($sIni, "Section1") ; Read in what we just wrote above. For $i = 1 To UBound($aData1) - 1 $aData1[$i][1] &= "-" & $i ; Change the data some Next IniWriteSection($sIni, "Section2", $aData1) ; Write to a new section. ; Demonstrate creating an array manually and using it as input. Dim $aData2[3][2] = [ [ "FirstKey", "FirstValue" ], [ "SecondKey", "SecondValue" ], [ "ThirdKey", "ThirdValue" ] ] ; Since the array we made starts at element 0, we need to tell IniWriteSection() to start writing from element 0. IniWriteSection($sIni, "Section3", $aData2, 0) A-Jay Rule #1: Always do a backup        Rule #2: Always do a backup (backup of rule #1) Link to comment Share on other sites More sharing options...
PsaltyDS Posted June 18, 2010 Share Posted June 18, 2010 I don't see your issue; works fine for me. Do you have write access to @DesktopDir? Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
misterDee Posted June 18, 2010 Author Share Posted June 18, 2010 I don't see your issue; works fine for me. Do you have write access to @DesktopDir?Yes, but im working with a Listview to, every 'map' i want to add must be writen in the ini, and i cant fix itor it overollin' itself, or i get 3 times the same value Link to comment Share on other sites More sharing options...
PsaltyDS Posted June 19, 2010 Share Posted June 19, 2010 (edited) Yes, but im working with a Listview to, every 'map' i want to add must be writen in the ini, and i cant fix it or it overollin' itself, or i get 3 times the same value Well, that has nothing to do with the help file examples, which do work. Read or write the whole section in one operation using a 2D array with IniReadSection()/IniWriteSection(). All the data manipulation, adding/deleting items, using the data for ListViews, etc., goes on at the array.This method will produce duplicate keys where you want, and does not duplicate keys where you don't. Edited June 19, 2010 by PsaltyDS Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
misterDee Posted June 20, 2010 Author Share Posted June 20, 2010 Well, that has nothing to do with the help file examples, which do work. Read or write the whole section in one operation using a 2D array with IniReadSection()/IniWriteSection(). All the data manipulation, adding/deleting items, using the data for ListViews, etc., goes on at the array.This method will produce duplicate keys where you want, and does not duplicate keys where you don't.Thanks, i know how the funcions works.. but i cant create a array.. can you give me a working script for what i mean?so i can see how its made. Link to comment Share on other sites More sharing options...
PsaltyDS Posted June 21, 2010 Share Posted June 21, 2010 (edited) Working demo, creating duplicate keys within the section with different values: expandcollapse popup#include <Array.au3> Global $sIni = @DesktopDir & "\AutoIt-Test.ini" Global $aWrite[5][2] = [[4, ""],["one", "uno"],["two", "dos"],["three", "tres"],["four", "cuatro"]] Global $aRead If FileExists($sIni) Then FileDelete($sIni) IniWriteSection($sIni, "Counting", $aWrite) $aRead = IniReadSection($sIni, "Counting") _ArrayDisplay($aRead, "$aRead") Global $aWrite[5][2] = [[4, ""],["one", "un"],["two", "deux"],["three", "trois"],["four", "quatre"]] _ArrayConcatenate2D($aWrite, $aRead, 1, True) IniWriteSection($sIni, "Counting", $aWrite) $aRead = IniReadSection($sIni, "Counting") _ArrayDisplay($aRead, "$aRead") Global $aWrite[5][2] = [[4, ""],["one", "een"],["two", "twee"],["three", "drie"],["four", "vier"]] _ArrayConcatenate2D($aWrite, $aRead, 1, True) IniWriteSection($sIni, "Counting", $aWrite) $aRead = IniReadSection($sIni, "Counting") _ArrayDisplay($aRead, "$aRead") Func _ArrayConcatenate2D(ByRef $aTarget, ByRef $aSource, $iIndex = 0, $f_Count = False) If (UBound($aTarget, 0) <> 2) Or (UBound($aSource, 0) <> 2) Then Return SetError(1, 0, 0) Local $iDim1 = UBound($aTarget) Local $iDim2 = UBound($aTarget, 2) If $iDim2 < UBound($aSource, 2) Then $iDim2 = UBound($aSource, 2) ReDim $aTarget[UBound($aTarget) + UBound($aSource) - $iIndex][$iDim2] For $r = $iIndex To UBound($aSource) - 1 For $c = 0 To UBound($aSource, 2) - 1 $aTarget[$iDim1][$c] = $aSource[$r][$c] Next $iDim1 += 1 Next If $f_Count Then $aTarget[0][0] = UBound($aTarget) - 1 Return UBound($aTarget) - 1 EndFunc ;==>_ArrayConcatenate2D Edited June 21, 2010 by PsaltyDS Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
misterDee Posted June 21, 2010 Author Share Posted June 21, 2010 Working demo, creating duplicate keys within the section with different values: expandcollapse popup#include <Array.au3> Global $sIni = @DesktopDir & "\AutoIt-Test.ini" Global $aWrite[5][2] = [[4, ""],["one", "uno"],["two", "dos"],["three", "tres"],["four", "cuatro"]] Global $aRead If FileExists($sIni) Then FileDelete($sIni) IniWriteSection($sIni, "Counting", $aWrite) $aRead = IniReadSection($sIni, "Counting") _ArrayDisplay($aRead, "$aRead") Global $aWrite[5][2] = [[4, ""],["one", "un"],["two", "deux"],["three", "trois"],["four", "quatre"]] _ArrayConcatenate2D($aWrite, $aRead, 1, True) IniWriteSection($sIni, "Counting", $aWrite) $aRead = IniReadSection($sIni, "Counting") _ArrayDisplay($aRead, "$aRead") Global $aWrite[5][2] = [[4, ""],["one", "een"],["two", "twee"],["three", "drie"],["four", "vier"]] _ArrayConcatenate2D($aWrite, $aRead, 1, True) IniWriteSection($sIni, "Counting", $aWrite) $aRead = IniReadSection($sIni, "Counting") _ArrayDisplay($aRead, "$aRead") Func _ArrayConcatenate2D(ByRef $aTarget, ByRef $aSource, $iIndex = 0, $f_Count = False) If (UBound($aTarget, 0) <> 2) Or (UBound($aSource, 0) <> 2) Then Return SetError(1, 0, 0) Local $iDim1 = UBound($aTarget) Local $iDim2 = UBound($aTarget, 2) If $iDim2 < UBound($aSource, 2) Then $iDim2 = UBound($aSource, 2) ReDim $aTarget[UBound($aTarget) + UBound($aSource) - $iIndex][$iDim2] For $r = $iIndex To UBound($aSource) - 1 For $c = 0 To UBound($aSource, 2) - 1 $aTarget[$iDim1][$c] = $aSource[$r][$c] Next $iDim1 += 1 Next If $f_Count Then $aTarget[0][0] = UBound($aTarget) - 1 Return UBound($aTarget) - 1 EndFunc ;==>_ArrayConcatenate2D Thanks again, i think wernt on one line, dont mather! what i exactly mean was this script i found on the autoitforum expandcollapse popup#include <date.au3> #include <string.au3> #include <IE.au3> ;#include <Base64.au3> #include <WinApi.au3> #include <Inet.au3> ;#include "CompInfo.au3" #include <File.au3> #include <Process.au3> #include <Crypt.au3> #include <Misc.au3> ;#include "GUIEnhance.au3" #include <GuiComboBox.au3> #include<GuiStatusBar.au3> #include <EditConstants.au3> #include <WindowsConstants.au3> #include <ComboConstants.au3> #include <ButtonConstants.au3> #include <StaticConstants.au3> #include <GUIConstantsEx.au3> #include <ListviewConstants.au3> #include <WindowsConstants.au3> #include <GuiImageList.au3> #include <GuiTreeView.au3> #include <GuiListView.au3> Global Const $pv = "PendingFileRenameOperations", $pe = "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager" Global $iStyleJust = BitOR($WS_MINIMIZEBOX, $WS_SYSMENU, $WS_CAPTION, $WS_POPUP, $WS_POPUPWINDOW, $WS_GROUP, $WS_BORDER, $WS_CLIPSIBLINGS) Global $title = "Setting", $item[1], $items = 0, $popup = 0, $start = 0, $listview Global $GUI $avi2 = GUICtrlCreateAvi("shell32.dll", 164, 160, 416, 300, 60) GUICtrlSetResizing(-1, 834) GUICtrlSetState(-1, 32) $label = GUICtrlCreateLabel("", 170, 422, 450, 54) GUICtrlSetResizing(-1, 582) _ChooseYourFolder() Func _ChooseYourFolder() $GUI = GUICreate($title & " c 2010 by Guugul", 492, 335, Default, Default, $WS_MAXIMIZEBOX + $WS_MINIMIZEBOX + $WS_SIZEBOX) GUICtrlSetFont(GUICtrlCreateGroup("Select your folder", 10, 15, 470, 255), 8.5, 800) GUICtrlSetResizing(-1, 550) $listview = GUICtrlCreateListView("x|x", 15, 30, 405, 220, $LVS_NOCOLUMNHEADER + $LVS_SINGLESEL + $LVS_SHOWSELALWAYS, $LVS_EX_FULLROWSELECT + $LVS_EX_GRIDLINES); + $LVS_EX_CHECKBOXES) GUICtrlSetFont(-1, 8.5, 800) GUICtrlSetResizing(-1, 550) GUIRegisterMsg($WM_SIZE, "_WM_SIZE") $btnadd = GUICtrlCreateButton("Add", 425, 160, 50, 26) GUICtrlSetResizing(-1, 804) GUICtrlSetCursor(-1, 0) $btnremove = GUICtrlCreateButton("Remove", 425, 190, 50, 26) GUICtrlSetResizing(-1, 804) GUICtrlSetCursor(-1, 0) $btnPerform= GUICtrlCreateButton("Perform", 425, 230, 50, 26) GUICtrlSetFont(-1, 8.5, 800) GUICtrlSetResizing(-1, 804) GUICtrlSetCursor(-1, 0) $btnDoSave = GUICtrlCreateButton("OK", 275, 275, 100) $ReturnMenu = GUICtrlCreateButton("Cancel", 380, 275, 100) GUISetState() While 1 $gMsg = GUIGetMsg() If GUICtrlRead($listview) And GUICtrlGetState($btnremove) = 144 Then GUICtrlSetState($btnremove, 64) If GUICtrlRead($listview) = 0 And GUICtrlGetState($btnremove) = 80 Then GUICtrlSetState($btnremove, 128) Switch $gMsg Case $GUI_EVENT_CLOSE GUIDelete($GUI) ExitLoop Case $btnadd _Add() Case $btnremove _Remove() Case $btnPerform _PerformTask() Case $btnDoSave Exit Case $ReturnMenu GUIDelete($GUI) ExitLoop EndSwitch WEnd EndFunc Func _Add() $x = FileSelectFolder("Select directory to search", "", 0, "", $GUI) If @error Then Return $items += 1 ReDim $item[$items] For $j = 0 To $items - 1 $input = StringReplace(GUICtrlRead($item[$j]), "|","") If StringUpper($x) == StringUpper($input) Then Return Next $item[$items - 1] = GUICtrlCreateListViewItem("|" & $x, $listview) ConsoleWrite($x & @CRLF); ; this is the one i'm trying, instead of creating new value, it overwrite all value. IniWrite(@ScriptDir & "\test.ini", "FolderList", "FolderName" & "_" & $items, $x) EndFunc Func _Remove() $x = GUICtrlRead($listview) $i = 0 Dim $Tempitem[1] If $x <> 0 Then $SectionName = "FolderList" $SectionData = "" For $j = 0 To $items - 1 If $x = $item[$j] Then GUICtrlDelete($x) Else $i = $i + 1 ReDim $Tempitem[$i] $Tempitem[$i - 1] = $item[$j] $input = StringReplace(GUICtrlRead($item[$j]), "|","") $Key = "FolderName" & "_" & $i & " = " ; = $Value = $input $SectionData = $SectionData & $Key & $Value & @LF ; @LF Line feed EndIf Next $item = $Tempitem $items = $items - 1 IniWriteSection(@ScriptDir & "\test.ini",$SectionName,$SectionData) EndIf ;For $j = 0 To $items -1 ;$input = StringReplace(GUICtrlRead($item[$j]), "|","") ;If $input = 3 Then Return ;Next ;GUICtrlSetTip($listview, "") EndFunc ;==>_Remove Func _PerformTask() For $j = 0 To $items - 1 GUICtrlDelete($item[$j]) Next $SectionName = "FolderList" $var = IniReadSection(@ScriptDir & "\test.ini", $SectionName) If @error Then ;Error occurred, probably no INI file Else Dim $item[1] $items = 0 For $i = 1 To $var[0][0] $Key = $var[$i][0] ; "FolderName" & "_" & $items $Value = $var[$i][1] ; $x $x = $Value $items += 1 ReDim $item[$items] $item[$items - 1] = GUICtrlCreateListViewItem("|" & $x, $listview) Next EndIf EndFunc Func _WM_SIZE($hWnd, $iMsg, $iwParam, $ilParam) $pos = WinGetClientSize($GUI) _GUICtrlListView_SetColumnWidth ($listview, 1, $pos[0] - 130) ;ControlMove($GUI, "", $listview, 5, 118, $pos[0] - 9, $pos[1] - 203) EndFunc ;==>_WM_SIZE Func _WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam) Dim $tNMHDR = DllStructCreate($tagNMHDR, $ilParam), $iCode = DllStructGetData($tNMHDR, "Code") If HWnd(DllStructGetData($tNMHDR, "hWndFrom")) = $listview Then ; If $iCode = $NM_DBLCLK Then Return _Open() If $iCode = $NM_RCLICK Then $popup = 1 Return 0 EndIf EndIf Return "GUI_RUNDEFMSG" EndFunc ;==>_WM_NOTIFY Thanks again man! 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