Jump to content

Quick Dynamic Array Question


Recommended Posts

Ok, I'm using the Excel.au3 UDF to return a column of information to me in an array. Now, for each element returned, I need to turn that element into it's own stand-alone array to hold data that's associated to it. So, how can I dynamically, on-the-fly create arrays that are named the same as each element in the original array?

Thanks

Link to comment
Share on other sites

#include <array.au3>
global $array_org[5] = ['a','b','c','d','e']
global $array_new[1]

redim $array_new[UBound($array_org)][2]; keep in mind that arrays are 0-based

for $i = 0 to UBound($array_org) - 1
    $array_new[$i][0] = $array_org[$i]
    $array_new[$i][1] = $i +1 
next

_ArrayDisplay($array_new)

Link to comment
Share on other sites

#include <array.au3>
global $array_org[5] = ['a','b','c','d','e']
global $array_new[1]

redim $array_new[UBound($array_org)][2]; keep in mind that arrays are 0-based

for $i = 0 to UBound($array_org) - 1
    $array_new[$i][0] = $array_org[$i]
    $array_new[$i][1] = $i +1 
next

_ArrayDisplay($array_new)

Thanks for the help, but I have a bit of a follow up/re adjustment to my question.

I need for the array to be named for one of the values in $array_org. But going into it, I won't know the values of that array until I run it. basically, as this loops through, I am going to have around 100 arrays or so. Each one needs to be named something different. So to take from your example above, I would have 5 different arrays when it's all said and done.

$a

$b

$c

$d

$e

But how can I tell AutoIT the name of these variable arrays at run time?

Does this question make any sense?

Thanks

Link to comment
Share on other sites

Thanks for the help, but I have a bit of a follow up/re adjustment to my question.

I need for the array to be named for one of the values in $array_org. But going into it, I won't know the values of that array until I run it. basically, as this loops through, I am going to have around 100 arrays or so. Each one needs to be named something different. So to take from your example above, I would have 5 different arrays when it's all said and done.

$a

$b

$c

$d

$e

But how can I tell AutoIT the name of these variable arrays at run time?

Does this question make any sense?

Thanks

Just use a 2D array:
#include <Array.au3>

Global $avOriginal[5] = ["a", "bee", "See", "13.0", "14"]

; Add attributes for each
Global $avNew[UBound($avOriginal) + 1][3] = [[UBound($avOriginal), "Length", "StringIsInt"]]
For $n = 0 To UBound($avOriginal) - 1
    $avNew[$n + 1][0] = $avOriginal[$n]
    $avNew[$n + 1][1] = StringLen($avOriginal[$n])
    $avNew[$n + 1][2] = StringIsInt($avOriginal[$n])
Next

; Display results
_ArrayDisplay($avNew, "$avNew")

:D

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