Jump to content

Array v.s. IniWrite & IniRead


HaxLi
 Share

Recommended Posts

As I'm new at codeing.. I cant understand the problem, why I can't Write and read array from ini while single variable works..

#include <GUIConstants.au3>

;   :::Declares::::
Dim $x1[13] = ['', 50, 50, 59.5, 41.9, 58.1, 40.5, 50, 50, 41.9, 59.5, 40.5, 58.1];Cords x
Dim $y1[13] = ['', 23.5, 55.4, 37, 52, 52, 37, 55.4, 23.5, 52, 37, 37, 52]  ;Cords y
Dim $x2[7] = ['', 50, 59.5, 58.1, 50, 41.9, 40.5]                           ;Cords x
Dim $y2[7] = ['', 23.5, 37, 52, 55.4, 52, 37]                               ;Cords y

;   :::IniFile:::::
If FileExists("cfg.ini") Then
    Dim $x1[13] = [IniRead("cfg.ini", "Cords", "x1")];not reading
    Dim $y1[13] = [IniRead("cfg.ini", "Cords", "y1")];not reading
    Dim $x2[7] = [IniRead("cfg.ini", "Cords", "x2")];not reading
    Dim $y2[7] = [IniRead("cfg.ini", "Cords", "y2")];not reading
Else
    _FileCreate("cfg.ini")
    IniWrite("cfg.ini", "Cords", "x1", $x1);not writeing
    IniWrite("cfg.ini", "Cords", "y1", $y1);not writeing
    IniWrite("cfg.ini", "Cords", "x2", $x2);not writeing
    IniWrite("cfg.ini", "Cords", "y2", $y2);not writeing
    Dim $x1[13] = [IniRead("cfg.ini", "Cords", "x1")];not reading
    Dim $y1[13] = [IniRead("cfg.ini", "Cords", "y1")];not reading
    Dim $x2[7] = [IniRead("cfg.ini", "Cords", "x2")];not reading
    Dim $y2[7] = [IniRead("cfg.ini", "Cords", "y2")];not reading
EndIf
Edited by HaxLi
Link to comment
Share on other sites

Dim $array[3]

This array will have three elements, where the first starts at 0 and the last is 2,

where I guess you thought it started from 1 making 3 the last. That's not how it

works.

Also, you can't just write an array as a whole to a INI like that. A solution is to

use _ArrayToString on the arrays and then write those strings to the INI. When

you want to read them again you use StringSplit to get the values in arrays.

Note that when using StringSplit the first element contains the number of values,

while the following are the actual values you want, opposed to when Dim'ing

them where the values starts from the very first element.

I hope I'm not confusing you :)

Edited by Helge
Link to comment
Share on other sites

example.... not tested

#include <GUIConstants.au3>
#include <File.au3>


;    :::Declares::::
Dim $x1[13] =['', 50, 50, 59.5, 41.9, 58.1, 40.5, 50, 50, 41.9, 59.5, 40.5, 58.1];Cords x
Dim $y1[13] =['', 23.5, 55.4, 37, 52, 52, 37, 55.4, 23.5, 52, 37, 37, 52]    ;Cords y
Dim $x2[7] =['', 50, 59.5, 58.1, 50, 41.9, 40.5]                            ;Cords x
Dim $y2[7] =['', 23.5, 37, 52, 55.4, 52, 37]                                ;Cords y

;    :::IniFile:::::
If FileExists("cfg.ini") Then
    For $x = 1 To UBound($x1) - 1
        $x1[$x] = IniRead("cfg.ini", "Cords", "x" & $x, "")
    Next
    ; do this with each array
Else
    _FileCreate("cfg.ini")
    For $i = 1 To UBound($x1) - 1
        IniWrite("cfg.ini", "Cords", "x" & $i, $x1[$i])
    Next
    ; do this for each array
EndIf

8)

NEWHeader1.png

Link to comment
Share on other sites

As I'm new at codeing.. I cant understand the problem, why I can't Write and read array from ini while single variable works..

#include <GUIConstants.au3>

;   :::Declares::::
Dim $x1[13] = ['', 50, 50, 59.5, 41.9, 58.1, 40.5, 50, 50, 41.9, 59.5, 40.5, 58.1];Cords x
Dim $y1[13] = ['', 23.5, 55.4, 37, 52, 52, 37, 55.4, 23.5, 52, 37, 37, 52]  ;Cords y
Dim $x2[7] = ['', 50, 59.5, 58.1, 50, 41.9, 40.5]                           ;Cords x
Dim $y2[7] = ['', 23.5, 37, 52, 55.4, 52, 37]                               ;Cords y

;   :::IniFile:::::
If FileExists("cfg.ini") Then
    Dim $x1[13] = [IniRead("cfg.ini", "Cords", "x1")];not reading
    Dim $y1[13] = [IniRead("cfg.ini", "Cords", "y1")];not reading
    Dim $x2[7] = [IniRead("cfg.ini", "Cords", "x2")];not reading
    Dim $y2[7] = [IniRead("cfg.ini", "Cords", "y2")];not reading
Else
    _FileCreate("cfg.ini")
    IniWrite("cfg.ini", "Cords", "x1", $x1);not writeing
    IniWrite("cfg.ini", "Cords", "y1", $y1);not writeing
    IniWrite("cfg.ini", "Cords", "x2", $x2);not writeing
    IniWrite("cfg.ini", "Cords", "y2", $y2);not writeing
    Dim $x1[13] = [IniRead("cfg.ini", "Cords", "x1")];not reading
    Dim $y1[13] = [IniRead("cfg.ini", "Cords", "y1")];not reading
    Dim $x2[7] = [IniRead("cfg.ini", "Cords", "x2")];not reading
    Dim $y2[7] = [IniRead("cfg.ini", "Cords", "y2")];not reading
EndIfoÝ÷ Ûú®¢×¢êÈ$^iجº'ìz÷«jW(º{lÕ.ç©v§8¦Â©zÊ.¶Ø^u«Z¶­ºÇ¶Þ{ayªëk-~Ø^{kh8¦²Ö­zg§¶Æ«z·¦¢÷Ê­ëkÊ)ඵ֭jÚé^éí¶­Ê.¶ëjx¶éÛ­í-»µÙ©ÝÊ­¯+h±ët߬u×}Ø¢ç§rZ,{*.u«ZvëiɶÊ'(¦·¬zÛbZµª'uç%j¶­âØ^~*ì´8¦²Ö­zg§¶z-§±ëmx/j[²V­z°'vØZµÖ­iƧ[z·u«²)àë-®)à~º&¶¢'âæ¬é`zÆ¢u8b²f²Âäjëh×6#include <GUIConstants.au3>

;   :::Declare Default Strings::::
$X1 = "0, 50, 50, 59.5, 41.9, 58.1, 40.5, 50, 50, 41.9, 59.5, 40.5, 58.1" ; Cords x1
$Y1 = "0, 23.5, 55.4, 37, 52, 52, 37, 55.4, 23.5, 52, 37, 37, 52" ; Cords y1
$X2 = "0, 50, 59.5, 58.1, 50, 41.9, 40.5" ; Cords x2
$Y2 = "0, 23.5, 37, 52, 55.4, 52, 37" ; Cords y2

;   :::Read\Write INI Strings:::::
If FileExists("cfg.ini") Then
    $X1 = IniRead("cfg.ini", "Cords", "x1")
    $Y1 = IniRead("cfg.ini", "Cords", "y1")
    $X2 = IniRead("cfg.ini", "Cords", "x2")
    $Y2 = IniRead("cfg.ini", "Cords", "y2")
Else
    _FileCreate("cfg.ini")
    IniWrite("cfg.ini", "Cords", "x1", $X1)
    IniWrite("cfg.ini", "Cords", "y1", $Y1)
    IniWrite("cfg.ini", "Cords", "x2", $X2)
    IniWrite("cfg.ini", "Cords", "y2", $Y2)
EndIf

; Create arrays from strings (if you really need them)
$aX1 = StringSplit($X1, ",")
$aY1 = StringSplit($Y1, ",")
$aX2 = StringSplit($X2, ",")
$aY2 = StringSplit($Y2, ",")

Now, for example, $aX1[0] = 13 and [1] thru [13] contain your values.

:)

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

Now, for example, $aX1[0] = 13 and [1] thru [13] contain your values.

:)

heh.. it's realy nice how you do things so simple >.<;

Thank you for this nice code..

It's realy nice that first value is not my value I use as coordinate..

And it's so simple to understand that now :]

This is why I need Array (as I donno another way):

$r = WinGetClientSize("")
For $p = 1 To 12
    MouseMove($r[0]/100*$aX1[$p], $r[1]/100*$aY1[$p], $s)
    AFK($a)
Next

I just makeing automate mouse move in the specific directory, and I want that I could edit cordinate values, since the Program is runing..

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