Jump to content

Redim deletes content of array


Recommended Posts

Redim deletes content of every row of 2D array once i redim it to have one more row, but if i access any content like $array[0][0] by console or just by assigning this value to some crap value just before redim then everything works fine.

I dont know why i am posting it as i will probably get "we need code" etc but this is nearly impossible to reproduce because everything works fine in a simple script, the thing is i have thousands lines of code :)

Still, what could possible be reason something like this happens?

Here is something that would work ok in normal code, but for some reason not in mine.

Func _ArrayAdd_Custom(ByRef $array, ByRef $add_array)
    Local $newsize = UBound($array) + 1

    ReDim $array[$newsize][8]
    For $column = 0 To 7
        $array[($newsize-1)][$column] = $add_array[$column]
    Next

EndFunc   ;==>_ArrayAdd_Custom
Edited by Aktonius
Link to post
Share on other sites

To solve this i simply changed it to

Func _ArrayAdd_Custom(ByRef $array, ByRef $add_array)
    Local $newsize = UBound($array) + 1
    Local $crapvalue

    ;WAKE UP ARRAY?!!? - after this redim wont delete content
    $crapvalue = $array[0][0]
  
    ReDim $array[$newsize][8]
    For $column = 0 To 7
        $array[($newsize-1)][$column] = $add_array[$column]
    Next

EndFunc   ;==>_ArrayAdd_Custom

Really one of weirdest issues i had with autoit, maybe calling this from wm_copydata has any connections to the problem, but then again i also tried to _array_add from dummy control, still same... Maybe it gives clues to someone with same issue one day

Edited by Aktonius
Link to post
Share on other sites

What version of AutoIt do you run?

I ran the following test script and get an array with 3 rows and 8 columsn as a result:

#include <array.au3>
Global $a2D[2][8] = [["1-1", "1-2", "1-3", "1-4", "1-5", "1-6", "1-7", "1-8"],["2-1", "2-2", "2-3", "2-4", "2-5", "2-6", "2-7", "2-8"]]
Global $a2Add[8] = ["3-1", "3-2", "3-3", "3-4", "3-5", "3-6", "3-7", "3-8"]
_ArrayAdd_Custom($a2D, $a2Add)
_ArrayDisplay($a2D)

Func _ArrayAdd_Custom(ByRef $array, ByRef $add_array)
    Local $newsize = UBound($array) + 1

    ReDim $array[$newsize][8]
    For $column = 0 To 7
        $array[($newsize - 1)][$column] = $add_array[$column]
    Next

EndFunc   ;==>_ArrayAdd_Custom
Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2021-06-05 - Version 1.5.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (NEW 2021-06-14 - Version 1.6.5.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (NEW 2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2019-12-03 - Version 1.5.1.0) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to post
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
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...