Jump to content

Recommended Posts

Posted

I've defined a function accepting three parameters, one of which is an array using byref. My function calls the UDF _ArrayAdd to add newly defined arrays to the array passed to the function. The function appears to run properly so far, but when I try to access one of the elements of the added arrays from the referenced main array, AutoIt generates a range error. I attempted to access the 2nd element of the sub array like this: $main_array[1][1]. This is clearly not a index out of bounds error. I've tested my function from within, and the successful execution of my function confirms that there is no error as to the number of elements in the array. The problem is, after I am done adding elements to the array in my function, I am unable to access the elements of the sub-array, or as it seems even the sub arrays themselves. I'd prefer not to post my code here, because I want to keep my project without competitors for now, but if it is absolutely necessary to show my code in order for you to help me, just ask, and I will display it.

  Reveal hidden contents

 

Posted

You should use _ArrayDisplay($main_array) to check if all elements that should be in the array, are actually in the array :mellow:

  • Moderators
Posted

WaitingForZion,

Do I understand that you are setting the newly-created arrays as elements of the first array? If that is the case, you cannot address the "second-order" arrays directly. You will have to extract them first:

#include <Array.au3>

Global $aBig_Array[2]

Global $aLittle_Array[2] = ["Element 1", "Element 2"]

$aBig_Array[1] = $aLittle_Array

_ArrayDisplay($aBig_Array)

$aExtracted_Array = $aBig_Array[1]

_ArrayDisplay($aExtracted_Array)

I hope that is clear. :mellow:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

  Reveal hidden contents

 

Posted

Nesting is not same thing as additional dimensions. If you've stored an array as an element in another array (nested them) then your syntax is wrong. The nested array must be copied out to its own temp variable to perform any operations on it.

If you're going to ask questions about references that don't work, post a short running demo script that will replicate the issue.

This demo is for nested arrays:

#include <Array.au3>

Global $aTemp1[2] = ["A", "B"]
Global $aTemp2[2] = ["C", "D"]
Global $aTemp3[1], $aWorking
Global $aParent[3] = [$aTemp1, $aTemp2, $aTemp3]

_UpdateNestedArray()
$aTemp3 = $aParent[2]
_ArrayDisplay($aTemp3, "$aTemp3")


Func _UpdateNestedArray()
    Local $aWorking1 = $aParent[0]
    Local $aWorking2 = $aParent[1]
    For $n = 0 To UBound($aWorking2) - 1
        _ArrayAdd($aWorking1, $aWorking2[$n])
    Next
    $aParent[2] = $aWorking1
EndFunc

:mellow:

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

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