Jump to content

Help: Copying Array datas to INI file


 Share

Recommended Posts

Hi all mates,

i'm not able to copy array datas to my ini file:

Global      $settings = @ScriptDir & "\settings.ini"
Global      $names[6]
global                     $s_names[6]

I use a button into a gui to open another window where I insert up to six names:

$namesineed= GUICreate("Form1", 138, 198, 379, 164)
$name1 = GUICtrlCreateInput("Input1", 8, 8, 121, 21)
$name2= GUICtrlCreateInput("Input2", 8, 32, 121, 21)
$name3= GUICtrlCreateInput("Input3", 8, 56, 121, 21)
$name4= GUICtrlCreateInput("Input4", 8, 80, 121, 21)
$name5= GUICtrlCreateInput("Input5", 8, 104, 121, 21)
$name6= GUICtrlCreateInput("Input6", 8, 128, 121, 21)
$exit   = GUICtrlCreateButton("Esci", 32, 160, 75, 25, 0)
GUISetState(@SW_HIDE, $WoW1Chars)

then i call it to open:

CASE $Buttontoopenwindow
        GUISetState(@SW_SHOW, $namesineed)
CASE $exit  
    _ArrayInsert($name1, 1, $Input1)
    _ArrayInsert($name1, 2, $Input2)
    _ArrayInsert($name1, 3, $Input3)
    _ArrayInsert($name1, 4, $Input4)
    _ArrayInsert($name1, 5, $Input5)
    _ArrayInsert($name1, 6, $Input6)
    IniWrite(@ScriptDir & "\Settings.ini", "Class1", "Users",GUICtrlRead($name1))
    $s_name1    = IniRead(@ScriptDir & "\Settings.ini", "Class1", "Users","")               "")
    GUISetState(@SW_HIDE, $WoW1Chars)

1) if i try (just to check) to add a _arraydisplay($name1,"...") i see rows 0 to 10 and numbers instead of the names i wrote. Moreover if i reopen the window and change datas, i see more lines on the _arraydisplay instead just 7 entries (0-6)

2) if i take a look at the .ini file i see something like

[Class0]
... my other things
... my other things
[Class1]
... my other things
... my other things
Users=0

and obviously i can't recall from the code the data I need (example i need to Read User5 of Class1

Can please someone help me to manage it?

Thanks everyone,

Marco

Link to comment
Share on other sites

You have to read the control to get the data with GuiCtrlRead(). You are sending the Control ID instead of the data. There is also no need for _ArrayInsert() since you already declared the array of the right size. For example:

$names[0] = GuiCtrlRead($Name1)

:)

P.S. Where did $Input1 thru $Input6 come from? You save the control IDs in $Name1 thru $Name6...

:lmao:

Edited 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

You have to read the control to get the data with GuiCtrlRead(). You are sending the Control ID instead of the data. There is also no need for _ArrayInsert() since you already declared the array of the right size. For example:

$names[0] = GuiCtrlRead($Name1)

:)

P.S. Where did $Input1 thru $Input6 come from? You save the control IDs in $Name1 thru $Name6...

:lmao:

Yes that was my mistake in pasting code to semplify it for the help:

i meant

CASE $exit  
    _ArrayInsert($name1, 1, $Name1)
    _ArrayInsert($name1, 2, $Name2)
    _ArrayInsert($name1, 3, $Name3)
    _ArrayInsert($name1, 4, $Name4)
    _ArrayInsert($name1, 5, $Name5)
    _ArrayInsert($name1, 6, $Name6)
    IniWrite(@ScriptDir & "\Settings.ini", "Class1", "Users",GUICtrlRead($name1))
    $s_name1    = IniRead(@ScriptDir & "\Settings.ini", "Class1", "Users","")               "")
    GUISetState(@SW_HIDE, $WoW1Chars)

Anyway, i did as you suggested and now first part is solved, since:

CASE $exit  
 $names[0] = GuiCtrlRead($Name1)
 $names[1] = GuiCtrlRead($Name2)
 $names[2] = GuiCtrlRead($Name3)
 $names[3] = GuiCtrlRead($Name4)
 $names[4] = GuiCtrlRead($Name5)

if i do an _arraydisplay i correctly see the datas,

BUT

IniWrite(@ScriptDir & "\Settings.ini", "Class1", "Users",GUICtrlRead($name1))
    $s_name1    = IniRead(@ScriptDir & "\Settings.ini", "Class1", "Users","")

doesn't work. It still return me "0" into Settings.ini so if i close and re-run application it gives me standard value (i already has a _loadsettings at beginning)

M.

Edited by marko001
Link to comment
Share on other sites

Troubleshooting 101: Isolate your problem

; IniWrite(@ScriptDir & "\Settings.ini", "Class1", "Users",GUICtrlRead($name1))
MsgBox(0, "Read", "$name1: " & GUICtrlRead($name1))
$s_name1 = IniRead(@ScriptDir & "\Settings.ini", "Class1", "Users", "")oÝ÷ Øí«l,¶¢ºÞrÛÚç­é墶Ø^¸­x)¢»b¢v®¶­sdæw&FR67&DF"fײgV÷C²b3#µ6WGFæw2æægV÷C²ÂgV÷C´6Æ73gV÷C²ÂgV÷CµW6W'2gV÷C²ÄuT7G&Å&VBb33c¶æÖS¥6VÆÄWV7WFR67&DF"fײgV÷C²b3#µ6WGFæw2æægV÷C²²Fò6÷r÷RFRfÆRgFW"FRw&FoÝ÷ Øí«]¡ë'ßÛp¢¹-¯,"¶¬zÛÚçºÚ"µÍ[UÜ]JØÜ [È ][ÝÉÌLÔÙ][ÜË[I][ÝË ][ÝÐÛÜÌI][ÝË ][ÝÕÙÉ][ÝË    ][ÝÐØ][ÝÊBÚ[^XÝ]JØÜ    [È ][ÝÉÌLÔÙ][ÜË[I][ÝÊHÈÈÚÝÈ[ÝHH[HYHÜ]

ETC ETC ETC...

[u]Helpful tips:[/u]If you want better answers to your questions, take the time to reproduce your issue in a small "stand alone" example script whenever possible. Also, make sure you tell us 1) what you tried, 2) what you expected to happen, and 3) what happened instead.[u]Useful links:[/u]BrettF's update to LxP's "How to AutoIt" pdfValuater's Autoit 1-2-3 Download page for the latest versions of Autoit and SciTE[quote]<glyph> For example - if you came in here asking "how do I use a jackhammer" we might ask "why do you need to use a jackhammer"<glyph> If the answer to the latter question is "to knock my grandmother's head off to let out the evil spirits that gave her cancer", then maybe the problem is actually unrelated to jackhammers[/quote]

Link to comment
Share on other sites

Well i tried with _arraydisplay and it shows correctly the datas.

Problem is that I (I think) try to write to settings.ini

IniWrite(@ScriptDir & "\Settings.ini", "Class1", "Users",GUICtrlRead($name1))

but it doesn't write the FULL Array, but just a "0"

What i would like to see in settings.ini is something like

[Class0]
... my other things
... my other things
[Class1]
... my other things
... my other things
Users=[aaa,bbb,ccc,ddd]  or Users = aaa,bbb,ccc,ddd

but i can't manage it...

M.

Link to comment
Share on other sites

Maybe I missed it.. but I dont see where you are telling it to write something from the array. All I see is:

IniWrite(@ScriptDir & "\Settings.ini", "Class1", "Users",GUICtrlRead($name1))

which is just directly reading the data from the control called $name1

$name1 is not the way an array is refferenced. Its more like $name[1]

Edited by SpookMeister

[u]Helpful tips:[/u]If you want better answers to your questions, take the time to reproduce your issue in a small "stand alone" example script whenever possible. Also, make sure you tell us 1) what you tried, 2) what you expected to happen, and 3) what happened instead.[u]Useful links:[/u]BrettF's update to LxP's "How to AutoIt" pdfValuater's Autoit 1-2-3 Download page for the latest versions of Autoit and SciTE[quote]<glyph> For example - if you came in here asking "how do I use a jackhammer" we might ask "why do you need to use a jackhammer"<glyph> If the answer to the latter question is "to knock my grandmother's head off to let out the evil spirits that gave her cancer", then maybe the problem is actually unrelated to jackhammers[/quote]

Link to comment
Share on other sites

but, Iniwrite writes to Settings.ini usually it's correct, i use for tons of other vars and it correctly writes to file.

But i don't know how to write it in form of Array to recall it later.

I never stored arrays on .ini files so i don't know how to correctly parse it.

If i do a

IniWrite(@ScriptDir & "\Settings.ini", "Class1", "Users",GUICtrlRead($name1[0]))

it stores the value but as simple record, not array, so if i process $name1[1] it overwrites the previous one, not writing as an array

Edited by marko001
Link to comment
Share on other sites

@azKay:

so it's correct to use guictrlread to populate the array from the input fields?

$names[0] = GuiCtrlRead($Name0)
$names[1] = GuiCtrlRead($Name1)
...

and then, once the array it's populated, conver it to string:

$memory_names=_ArrayToString($names, @TAB, 0, 1))

And now? how can a) add this string to the settings.ini and :) load the 2 values (i.e. i need to retrieve the n-esime value of the array?)

Thanks mate!

Edited by marko001
Link to comment
Share on other sites

Anytime :)

EDIT::

Just do what you did with your iniwrite, Replace the GUICtrlRead($names) with $memory_names.

Edited by AzKay
# MY LOVE FOR YOU... IS LIKE A TRUCK- #
Link to comment
Share on other sites

Maybe like this but you may need to add err trap and also reverse it in you want it to write but the concept is similar.

Opt("MustDeclareVars", 1)
Opt("GuiOnEventMode", 1)


Global $GUI, $i, $j, $ini, $dummy, $Input[6], $arr

$ini = @ScriptDir & "\Test.ini"
$dummy = IniRead($ini, "SectionArr", "Arr", '')
$arr = StringSplit($dummy, ',')

$GUI = GUICreate("Ini read/write", 180, 100)

For $i = 0 To 2
    For $j = 0 To 1
        $Input[$i+$j] = GUICtrlCreateInput($arr[$i+$j+1], $i * 55 + 10, $j * 25 + 10, 50, 20)
    Next
Next

GUICtrlCreateButton("Close", 60, 65, 60, 23)
GUICtrlSetOnEvent(-1, "_OnClose")
GUISetOnEvent(-3, "_OnClose")

GUISetState()

While 1
    Sleep(150)
WEnd


Func _OnClose()
    
    GUIDelete($GUI)
    Exit
EndFunc


#cs  Test.ini content:

[SectionFirst]
FirstFirst="FirstFirst"
FirstSecond="FirstSecond"
FirstLast="FirstLast"


[SectionSecond]
SecondFirst="SecondFirst"
SecondSecond="SecondSecond"
SecondLast="SecondLast"


[SectionLast]
LastFirst="LastFirst"
LastSecond="LastSecond"
LastLast="LastLast"


[SectionArr]
Arr="aa,ab,ac,ad,ba,bb"
#ce
Link to comment
Share on other sites

Trying to parse it but

Array variable has incorrect number of subscripts or subscript dimension range exceeded.:
$Input[$i+$j] = GUICtrlCreateInput($arr[$i+$j+1], $i * 55 + 10, $j * 25 + 10, 50, 20)
$Input[$i+$j] = GUICtrlCreateInput(^ ERROR

@azkay, ok for writing it to Settings.ini

But how to read it for future use? I mean if i want at load to load the datas and copy them to the gui?

Link to comment
Share on other sites

hmm... Read the .ini content at the bottom of the code because in this case the array splitting to 6 subscripts with $arr[0] as the counter so if you got like 20 subscripts you need to omit the initialization of the control's text in this loop because it's only 6... anyway this kind of loop and IniRead works fine for me

Link to comment
Share on other sites

Trying to parse it but

Array variable has incorrect number of subscripts or subscript dimension range exceeded.:
$Input[$i+$j] = GUICtrlCreateInput($arr[$i+$j+1], $i * 55 + 10, $j * 25 + 10, 50, 20)
$Input[$i+$j] = GUICtrlCreateInput(^ ERROR

@azkay, ok for writing it to Settings.ini

But how to read it for future use? I mean if i want at load to load the datas and copy them to the gui?

For reading, You could look at IniRead(), then if you needed it into an array you could _StringToArray().
# MY LOVE FOR YOU... IS LIKE A TRUCK- #
Link to comment
Share on other sites

basically i don't need them back in array but i need them to be placed, at _loadsettings(), in the GUI:

$s_name1    = IniRead(@ScriptDir & "\Settings.ini", "Class1", "Users","")               "")

right now returns me the string I created in settings.ini

how to put it back to $name1 ... $name6 Inputs?

M.

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