Jump to content

"error: Statement cannot be just an expression" when trying to assign value


Go to solution Solved by Nine,

Recommended Posts

I read a file into array of arrays 

Local $programFileArray
    _FileReadToArray($programFile, $programFileArray, "2", ',')

Because its array of arrays,  I read it like

Dim $pointsToAdjust[0]

For $i = 0 To UBound($programFileArray)-1
    If UBound($programFileArray[$i]) < 5 Then ContinueLoop ;I dont care lines with less than 5 elements

    If (StringInStr(($programFileArray[$i])[0], $pointName & " : POINT")) == 0 Then 
        ContinueLoop ;not the line we look for
    Else
        _ArrayAdd($pointsToAdjust, $i) ;Add the index of an element to the list to remember
        ExitLoop
    EndIf
Next

Now I wanna edit the array so I can call "_FileWriteFromArray" later with my modified data.

I check the value I wanna edit:

For $point in $pointsToAdjust
        $testprogramFileArray = $programFileArray ;So the changes here dont affect next iteration
        ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : ($testprogramFileArray[$point])[7] = ' & ($testprogramFileArray[$point])[7] + 2 & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console <<-- This reads value and adds 2 to it correctly in console output
        ($testprogramFileArray[$point])[7] = ($testprogramFileArray[$point])[7] + 2 ;<<-- This fails

    Next

It fails with
 image.png.582121f4ef0db3de655f9b094eed28b9.png

 

"C:\__work\AutoitSkripts\__PointMouse_fastSim.au3"(1357,78) : error: Statement cannot be just an expression.
        ($testprogramFileArray[$point])[7] = ($testprogramFileArray[$point])[7] + 2
        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
C:\__work\AutoitSkripts\__PointMouse_fastSim.au3 - 1 error(s), 0 warning(s)

Why exactly? The value inside I can read, why cant I assign it a new value? (The +2 is just illustrative)

How would I go about updating that value so I can _FileWriteFromArray Later?

 

Thanks for any help

Edited by MaximusCZ
Link to comment
Share on other sites

  • Solution

You just cannot do that the way you wrote.  Use something like this:

 

Local $a1 = [1,2,3,4,5]
Local $a2 = [5,6,7,8,9,0]
Local $a3 = [4,5,6]
Local $a = [$a1, $a2, $a3]

ConsoleWrite(($a[2])[1] & @CRLF)

ArrayAssign ($a[2], 1, 100)

ConsoleWrite(($a[2])[1] & @CRLF)

Func ArrayAssign(ByRef $arr, $idx, $value)
  $arr[$idx] = $value
EndFunc

 

Edited by Nine
typo
Link to comment
Share on other sites

35 minutes ago, Jos said:

Why are there brackets in that statement?

Because it isnt 2D array, but an array of arrays. just $var[$i][$o] doesnt work here 

 

34 minutes ago, Nine said:

You just cannot do that the way you wrote.  Use something like this:

 

Local $a1 = [1,2,3,4,5]
Local $a2 = [5,6,7,8,9,0]
Local $a3 = [4,5,6]
Local $a = [$a1, $a2, $a3]

ConsoleWrite(($a[2])[1] & @CRLF)

ArrayAssign ($a[2], 1, 100)

ConsoleWrite(($a[2])[1] & @CRLF)

Func ArrayAssign(ByRef $arr, $idx, $value)
  $arr[$idx] = $value
EndFunc

 

Works perfectly, thanks! :) 

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