Jump to content

[solved: typo] \ Script updates wrong array


Go to solution Solved by jchd,

Recommended Posts

Hi,

I use this kind of a function to update my arrays (stripped off anything not necessary):

Func UpdateArray (ByRef $upArray, $addvariable)
        $upArray[0][0] += 1 
        $upArray[0][$upArray[0][0]] = $addvariable
EndFunc

I call this function like 1000 times to update $arrayA and $arrayB. It updates $arrayA ok then it switches to $arrayB, but then it does not switch back to $arrayA.

Things get interesting. I have split the call into this and the result is the same:

If $condition Then
    $arrayA[0][0] += 1  
    $arrayA[0][$arrayA[0][0]] = $addvariable
    MsgBox (0, "A", $addvariable)
Else
    $arrayB[0][0] += 1  
    $arrayB[0][$arrayB[0][0]] = $addvariable
    MsgBox (0, "B", $addvariable
EndIf

Msg displays correct letter BUT then the variable is in the wrong array!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! How?

Can I send the name of the variable directly to the MsgBox? I mean using the MsgBox  that would display the name of the array which we are working on.

 

Edited by antai
Link to comment
Share on other sites

  • antai changed the title to Script updates wrong array

 

you don't need it because that's what you use in the $upArray parameter when you call the UpdateArray function.
according to my knowledge what is missing is ReDim to resize the existing array.

#include <AutoItConstants.au3>
#include <Array.au3>

Local $aArrayA[51][3]
$aArrayA[0][0] = 50
For $i = 1 To $aArrayA[0][0]
    $aArrayA[$i][0] = "Var_" & $i
Next
Local $Var = "new"
UpdateArray($aArrayA, $Var)
UpdateArray($aArrayA, "new2")
_ArrayDisplay($aArrayA, "$aArrayA")
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Local $aArrayB[11][5]
$aArrayB[0][0] = 10
For $i = 1 To $aArrayB[0][0]
    $aArrayB[$i][0] = "Var_" & $i
Next
Local $Var = "new"
UpdateArray($aArrayB, $Var)
_ArrayDisplay($aArrayB, "$aArrayB")
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
_ArrayAdd($aArrayB, "New with _ArrayAdd")
$aArrayB[0][0] += 1

_ArrayAdd($aArrayB, "another|with|_ArrayAdd")
$aArrayB[0][0] += 1

_ArrayDisplay($aArrayB, "$aArrayB")
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Func UpdateArray(ByRef $upArray, $addvariable, $line = @ScriptLineNumber)
    ConsoleWrite("- Call from Line Number:" & $line & @CRLF)
    Local $iRows = UBound($upArray, $UBOUND_ROWS)     ; Total number of rows.
    Local $iCols = UBound($upArray, $UBOUND_COLUMNS)  ; Total number of columns.

    ConsoleWrite("$iRows:" & $iRows & ", $iCols:" & $iCols & @CRLF)

    ReDim $upArray[$iRows + 1][$iCols]

    $upArray[0][0] = $iRows
    $upArray[$iRows][0] = $addvariable

EndFunc   ;==>UpdateArray

Edit:
You shows us the function, but nowhere how you call it

Edited by ioa747
update

I know that I know nothing

Link to comment
Share on other sites

  • Solution

@antai your code refers to $uArray. What's that?

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

20 hours ago, ioa747 said:

 how you call it

This causes loss of data during the array update:

If $condition Then
        UpdateArray ($arrayA, $variable)
;       UpdateArray ($arrayB, $variable)
    Else
;       UpdateArray ($arrayA, $variable)
        UpdateArray ($arrayB, $variable)
    EndIf

This works fine. All the data in the arrayA:

If $condition Then
        UpdateArray ($arrayA, $variable)
;       UpdateArray ($arrayB, $variable)
    Else
        UpdateArray ($arrayA, $variable)
;       UpdateArray ($arrayB, $variable)
    EndIf

This works fine, All thedata in the arrayB:

If $condition Then
;       UpdateArray ($arrayA, $variable)
        UpdateArray ($arrayB, $variable)
    Else
;       UpdateArray ($arrayA, $variable)
        UpdateArray ($arrayB, $variable)
    EndIf

 

Edited by antai
Link to comment
Share on other sites

SOLVED: typo.

FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF AAAAAAAAAAAAAAAAAAA CK!! 15 hours of testing and sleep deprivation because of a simple typo.

Thanks guys, you really helped me.

Your questions pointed me to the right direction.

For those who care: the function is way longer and I several times update the

$upArray[0][0]

I mistyped that in one single occasion causing it to not get updated under certain conditions. No difference when throwing data only to a single array as it always goes up but more arrays caused problems due to calling a completely different variable!

Link to comment
Share on other sites

  • antai changed the title to [solved: typo] \ Script updates wrong array

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