Jump to content

Writing to ini


edisom
 Share

Recommended Posts

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. 

Link to comment
Share on other sites

  • Moderators

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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

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 by edisom
Link to comment
Share on other sites

  • Moderators

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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

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
Link to comment
Share on other sites

 

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]]

Link to comment
Share on other sites

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.
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...