edisom Posted January 12, 2014 Posted January 12, 2014 I am now working on writing to ini file. It looks like this: [Config] 1=username1 pass1 2=username2 pass2 I am trying to read the biggest key Local $aArray = IniReadSection("config.ini","Config") MsgBox(1," ",_ArrayMax($aArray,1)) But it is not working. I want to read key number to add 1 and write new data to ini with +1 key.
Moderators Melba23 Posted January 12, 2014 Moderators Posted January 12, 2014 edisom,_ArrayMax only works on 1D arrays - so you will have to extract the key values like this:#include <Array.au3> ; Load the 2D array from the ini file Local $aArray = IniReadSection("config.ini", "Config") _ArrayDisplay($aArray, "2D Array", Default, 8) ; Create and fill 1D array with the key values Local $a1D_Array[UBound($aArray)] For $i = 0 To UBound($aArray) - 1 $a1D_Array[$i] = $aArray[$i][0] Next _ArrayDisplay($a1D_Array, "1D Array", Default, 8) ; Find highest value MsgBox(1, " ", _ArrayMax($a1D_Array, 1))All clear? M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
edisom Posted January 12, 2014 Author Posted January 12, 2014 (edited) That is working like a charm . Next step is to Local $a1D_Array[UBound($aArray)] For $i = 0 To UBound($aArray) - 1 $a1D_Array[$i] = $aArray[$i][1] Next _ArrayDisplay($a1D_Array, "1D Array", Default, 8) ; I have got here Ini values GUICtrlSetData($List1,$a1D_Array) I'd like to set Ini values this time to ListBox I predict I need to create a loop for that:P And list options are separated with | PS. Whats the code for colorful code? Edited January 12, 2014 by edisom
Moderators Melba23 Posted January 12, 2014 Moderators Posted January 12, 2014 edisom,You have a couple of possibilities - I explain both in this post. Please ask if you have any questions about the code therein. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
edisom Posted January 15, 2014 Author Posted January 15, 2014 Thx for help. Now Ive got here problem. I dont know if i understand loops well. Such error occurs: ==> Array variable subscript badly formatted.: Local $b1D_Array[uBound($bArray)] Local $b1D_Array[^ ERROR Func _addtxt() $path = FileOpenDialog("Import form txt",@DesktopDir,"(*.txt)") $read = FileRead($path) $read1 = StringReplace($read,":"," ") $split = StringSplit($read1,@CR) _ArrayDisplay($split) For $i=1 to $split[0] $bArray = IniReadSection("config.ini", "Config") ; Create and fill 1D array with the key values Local $b1D_Array[UBound($bArray)] For $o = 0 To UBound($bArray) - 1 $b1D_Array[$o] = $bArray[$o][0] Next ; Find highest value $max = _ArrayMax($b1D_Array, 1) global $maxplusforread = $max+1 $sDate = @MDAY & "/" & @Mon & "/" & StringRight(@Year, 2) IniWrite("config.ini","Config",$maxplusforread,$sDate&" "&$split[$i]&" |") Next Call("_refresh") EndFunc
michaelslamet Posted January 15, 2014 Posted January 15, 2014 Thx for help. Now Ive got here problem. I dont know if i understand loops well. Such error occurs: ==> Array variable subscript badly formatted.: Local $b1D_Array[uBound($bArray)] Local $b1D_Array[^ ERROR Func _addtxt() $path = FileOpenDialog("Import form txt",@DesktopDir,"(*.txt)") $read = FileRead($path) $read1 = StringReplace($read,":"," ") $split = StringSplit($read1,@CR) _ArrayDisplay($split) For $i=1 to $split[0] $bArray = IniReadSection("config.ini", "Config") ; Create and fill 1D array with the key values Local $b1D_Array[UBound($bArray)] For $o = 0 To UBound($bArray) - 1 $b1D_Array[$o] = $bArray[$o][0] Next ; Find highest value $max = _ArrayMax($b1D_Array, 1) global $maxplusforread = $max+1 $sDate = @MDAY & "/" & @Mon & "/" & StringRight(@Year, 2) IniWrite("config.ini","Config",$maxplusforread,$sDate&" "&$split[$i]&" |") Next Call("_refresh") EndFunc Your $b1D_Array is a 2D array, so try: Local $b1D_Array[uBound($bArray)[0]]
jdelaney Posted January 15, 2014 Posted January 15, 2014 Here you go: #include <File.au3> _FileCreate("Some.ini") FileWrite("Some.ini", "[Config]" & @CRLF & "1=username1 pass1" & @CRLF & "2=username2 pass2") $iMax = 0 $aConfig = IniReadSection("Some.ini", "Config") For $i = 1 To UBound($aConfig)-1 If Number($aConfig[$i][0]) > $iMax Then $iMax = Number($aConfig[$i][0]) Next IniWrite("Some.ini","Config",$iMax+1,"username" & $iMax+1 & " pass" & $iMax+1) ConsoleWrite(FileRead("Some.ini") & @CRLF) output: [Config] 1=username1 pass1 2=username2 pass2 3=username3 pass3 IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
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