Jump to content

ASSIGN


Recommended Posts

Hello together.

i want to read from a file a varible and value and set them.

Read from a ini file is no problem.

But i can´t set the value to a array.

Does some one have a idee to set values to array?

assign with normal variable works assign("$variable","value")

--------------------

Global $variable

Global $variable1[5]

Assign("variable","2")

MsgBox(4096, "", $variable)

Assign("variable1[0]","2")

MsgBox(4096, "", $variable1[0])

Edited by MrTechnik
Link to comment
Share on other sites

Global $variable

Global $variable1[5]

Assign("variable","2")

MsgBox(4096, "", $variable)

The last two lines would not be possible anyway : what index (into the array) is the computer supposed to take ?

Another thing is that assigning a value/string to a simple variable with the same name as an array will automatically destroy the array (and vise-verse)

Assign("variable1[0]","2")

MsgBox(4096, "", $variable1[0])

This would be done like you learned in school, with a simple "=" :
Global $variable[5]

$variable[0]=2
$variable[1]="blue"

MsgBox(4096, "", "The Value is " & $variable[0] & @crlf & "The Color is " & $variable[1])
Edited by BitRot
Link to comment
Share on other sites

Hello together.

i want to read from a file a varible and value and set them.

Read from a ini file is no problem.

But i can´t set the value to a array.

Does some one have a idee to set values to array?

assign with normal variable works assign("$variable","value")

--------------------

Global $variable

Global $variable1[5]

Assign("variable","2")

MsgBox(4096, "", $variable)

Assign("variable1[0]","2")

MsgBox(4096, "", $variable1[0])

With IniReadSectionNames() and IniReadSection() already putting the data in an array, what's the point? :lmao:

Posting an example of your data file and how you want to access the data would help.

:ph34r:

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

Thanks for your help.

at the moment I Include the following file to set arrays with informations

like.

$array_rb3_0[00][01] = $gui_checked

$array_rb3_0[01][01] = $gui_unchecked

$array_rb3_0[02][01] = $gui_unchecked

$array_rb3_0[03][01] = $gui_unchecked

$array_rb3_0[00][02] = "SW"

$array_rb3_0[01][02] = "BL"

$array_rb3_0[02][02] = "WH"

$array_rb3_0[03][02] = "no Change"

$array_rb3_0[00][03] = ""

$array_rb3_0[01][03] = ""

$array_rb3_0[02][03] = ""

$array_rb3_0[03][03] = ""

$array_rb3_0[00][04] = "0 0 0"

$array_rb3_0[01][04] = "0 0 255"

$array_rb3_0[02][04] = "255 255 255"

$array_rb3_0[03][04] = ""

and i want to set this array by using ini read.

I can read these information like inireadsection but i have to convert/assign this informations (variable & value) to the correct array i needed. I can´t use the iniread array directly.

Thanks a lot

Script:

#include <Array.au3>

DIM $inifile[30]

DIM $array_rb3_0[4][6]

DIM $profil

$profil="X:\PROFIL1.AUP"

$inifile = $profil

msgbox(4096,"",$inifile)

$ARRAY_PARAMETER= IniReadSection($inifile, "RB3_0_01")

If @error Then

MsgBox(4096, "", "Error occured, probably no INI file.")

Else

If $array_parameter[0][0] < 16 then

msgbox(4096,"","Error with ini file")

Else

msgbox (4096,"",$array_parameter[0][0])

For $i = 1 To ($ARRAY_PARAMETER[0][0])

msgbox (4096,"",$i)

;$array_rb3_0[$i-1][01]=$ARRAY_PARAMETER[$i][1]

;$array_rb3_0[$i-1][02]=$ARRAY_PARAMETER[$i+4][1]

;$array_rb3_0[$i-1][03]=$ARRAY_PARAMETER[$i+8][1]

;$array_rb3_0[$i-1][04]=$ARRAY_PARAMETER[$i+12][1]

;msgbox(4096,"",$array_rb3_0[$i-1][01] & " - " & $array_rb3_0[$i-1][02] & " - " & $array_rb3_0[$i-1][03] & " - " & $array_rb3_0[$i-1][04],1)

msgbox(4096,"",string($array_PARAMETER[$i][0]) & " * " & string($ARRAY_PARAMETER[$i][1]))

assign(($array_PARAMETER[$i][0]),($ARRAY_PARAMETER[$i][1]))

Next

For $i = 1 To 4

msgbox(4096,"",$array_rb3_0[$i-1][01] & " - " & $array_rb3_0[$i-1][02] & " - " & $array_rb3_0[$i-1][03] & " - " & $array_rb3_0[$i-1][04],1)

next

msgbox(4096,"",$stringx)

EndIf

EndIf

************

INI-FILE NAMED *.AUP

X:\PROFIL1.AUP

[sTATUS]

ARRAY [xx] [00] = ID

ARRAY [xx] [01] = Status (1 für Checked / 4 für unchecked)

ARRAY [xx] [02] = Anzeigetext

ARRAY [xx] [03] = TIP

ARRAY [xx] [04] = AUFRUF oder WERT

[RB3_0_01]

$array_rb3_0[00][01] = 4

$array_rb3_0[01][01] = 1

$array_rb3_0[02][01] = 4

$array_rb3_0[03][01] = 4

$array_rb3_0[00][02] = 1BL

$array_rb3_0[01][02] = 1Sw

$array_rb3_0[02][02] = 1WH

$array_rb3_0[03][02] = 1no Change

$array_rb3_0[00][03] = x

$array_rb3_0[01][03] = y

$array_rb3_0[02][03] = z

$array_rb3_0[03][03] = ""

$array_rb3_0[00][04] = 0 0 255

$array_rb3_0[01][04] = 0 0 0

$array_rb3_0[02][04] = 255 255 255

$array_rb3_0[03][04] = ""

[RB3_0_01]

...

Edited by MrTechnik
Link to comment
Share on other sites

Thanks for your help.

at the moment I Include the following file to set arrays with informations

like.

I promised to look at it when I got a chance: Here it is, done with arrays. Could be done with multiple 1D arrays, but you seem to already be into 2D arrays, so:

$IniFile = @ScriptDir & "\PROFIL1.AUP"
If Not FileExists($IniFile) Then
    MsgBox(16, "Error!", "INI file not found: " & $IniFile)
    Exit
EndIf

; For all four sections...
For $s = 1 To 4
    $IniSec = "Sec_" & $s
    $aIniSec = IniReadSection($IniFile, $IniSec)
    If Not @error Then
        ; Create 2D array to populate from the ini file
        Dim $aSettings[4][5]
        If $aIniSec[0][0] = 17 Then
            For $i = 1 To ($aIniSec[0][0])
                ; Get the array subscripts from the key name
                $aIndexes = _TestKey($aIniSec[$i][0])
                If Not @error Then
                    $aSettings[$aIndexes[0]][$aIndexes[1]] = $aIniSec[$i][1]
                Else
                    MsgBox(16, "Error!", "Malformed INI section key name: " & $aIniSec[$i][0])
                EndIf
            Next
        Else
            MsgBox(16, "Error!", "INI file section had other than 17 keys.  Count = " & $aIniSec[0][0])
        EndIf
    Else
        MsgBox(16, "Error!", "Error reading section from ini file!")
        Exit
    EndIf
    
    _ArrayDisplay2D($aSettings, "Settings: " & $s)
Next


; =========================================================
; Function _TestKey()
;   Splits input string formatted "a_b"
;   Verifies proper format and converts to two numbers
;   On success returns 2-element array:  [0] = a, [1] = b
;   On failure sets @error = 1
; =========================================================
Func _TestKey($sInput)
    Local $aReturn[2], $n
    Local $aSplit = StringSplit($sInput, "_")
    If $aSplit[0] = 2 Then
        For $n = 1 To 2
            If Number($aSplit[$n]) >= 0 And Number($aSplit[$n]) <= 4 Then
                $aReturn[$n - 1] = Number($aSplit[$n])
            Else
                Return SetError(2, 0, 0)
            EndIf
        Next
        Return $aReturn
    Else
        Return SetError(1, 0, 0)
    EndIf
EndFunc   ;==>_TestKey


; =========================================================
; Function _ArrayDisplay2D()
;   Displays the input 2-D array in a message box with given title
; =========================================================
Func _ArrayDisplay2D($aInput, $sTitle)
    Local $Msg = "", $a, $b
    For $a = 0 To UBound($aInput) - 1
        For $b = 0 To UBound($aInput, 2) - 1
            $Msg &= @CRLF & "[" & $a & "][" & $b & "] = " & $aInput[$a][$b]
        Next
        $Msg &= @CRLF
    Next
    MsgBox(64, $sTitle, $Msg)
EndFunc   ;==>_ArrayDisplay2D

Here's the PROFIL.AUP file, formatted as an ini, put in the @ScriptDir:

CODE
; Format of PROFIL1.AUP

; [sec_n]

; 0_0 = ID

; x_1 = Status (1 für Checked / 4 für unchecked)

; x_2 = Anzeigetext

; x_3 = TIP

; x_4 = AUFRUF oder WERT

[sec_1]

0_0 = Section One

0_1 = 4

0_2 = 1BL

0_3 = x

0_4 = 0 0 255

1_1 = 1

1_2 = 1Sw

1_3 = y

1_4 = 0 0 0

02_01 = 4

02_02 = 1WH

02_03 = z

02_04 = 255 255 255

03_01 = 4

03_02 = 1no Change

03_03 =

03_04 =

[sec_2]

00_00 = Section Two

00_01 = A

00_02 = 2BL

00_03 = B

00_04 = 0 0 255

01_01 = C

01_02 = 2Sw

01_03 = D

01_04 = 0 0 0

02_01 = E

02_02 = 2WH

02_03 = F

02_04 = 255 255 255

03_01 = G

03_02 = 2no Change

03_03 = H

03_04 =

[sec_3]

00_00 = Section Three

00_01 = Z

00_02 = 3BL

00_03 = Y

00_04 = 0 0 255

01_01 = X

01_02 = 3Sw

01_03 = W

01_04 = 0 0 0

02_01 = V

02_02 = 3WH

02_03 = U

02_04 = 255 255 255

03_01 = T

03_02 = 3no Change

03_03 = S

03_04 =

[sec_4]

00_00 = Section Four

00_01 = 4.4

00_02 = 4BL

00_03 = 4.x

00_04 = 0 0 255

01_01 = 4.1

01_02 = 4Sw

01_03 = 4.y

01_04 = 0 0 0

02_01 = 4.4

02_02 = 4WH

02_03 = 4.z

02_04 = 255 255 255

03_01 = 4.4

03_02 = 4no Change

03_03 = 4.0

03_04 =

I had no idea what this data was supposed to represent, so I took liberties in modifying it to give me something to look at for results.

: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

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