Jump to content

Using Assign() - Eval() - _ArrayAdd() - _ArrayInsert() together


Recommended Posts

Hi,

I try to create X arrays ($array1, $array2, $array3... $arrayX) where X must be defined by users. So it may be any number.

Before starting write the final script i did some tests.

After many tests, i don't understand why the first code works and the second... does not...

#include <Array.au3>

for $n = 1 to 3

Assign ("var" & $n, _ArrayCreate("a" & $n, "b" & $n, "c" & $n, "d" & $n , "e" & $n), 2)
_ArrayDisplay( Eval("var" & $n), "test" & $n)

next

ExitoÝ÷ Ù«­¢+Ø¥¹±Õ±ÐíÉÉä¹ÔÌÐì()½ÈÀÌØí¸ôÄѼÌ()ÍÍ¥¸ ÅÕ½ÐíÙÈÅÕ½ÐìµÀìÀÌØí¸°}ÉÉå
ÉÑ ÅÕ½ÐíÅÕ½ÐìµÀìÀÌØí¸°ÅÕ½ÐíÅÕ½ÐìµÀìÀÌØí¸°ÅÕ½ÐíÅÕ½ÐìµÀìÀÌØí¸°ÅÕ½ÐíÅÕ½ÐìµÀìÀÌØí¸°ÅÕ½ÐíÅÕ½ÐìµÀìÀÌØí¸¤°È¤)}ÉÉå¥ÍÁ±ä Ù° ÅÕ½ÐíÙÈÅÕ½ÐìµÀìÀÌØí¸¤°ÅÕ½ÐíÑÍÐÅÕ½ÐìµÀìÀÌØí¸¤()}ÉÉå Ù° ÅÕ½ÐíÙÈÅÕ½ÐìµÀìÀÌØí¸¤°ÅÕ½ÐíÅÕ½Ðì¤)}ÉÉå¥ÍÁ±ä Ù° ÅÕ½ÐíÙÈÅÕ½ÐìµÀìÀÌØí¸¤°ÅÕ½ÐíÑÍÐÅÕ½ÐìµÀìÀÌØí¸¤()}ÉÉå%¹ÍÉÐ Ù° ÅÕ½ÐíÙÈÅÕ½ÐìµÀìÀÌØí¸¤°È°ÅÕ½ÐíUÁÑÅÕ½Ðì¤)}ÉÉå¥ÍÁ±ä Ù° ÅÕ½ÐíÙÈÅÕ½ÐìµÀìÀÌØí¸¤°ÅÕ½ÐíÑÍÐÅÕ½ÐìµÀìÀÌØí¸¤()¹áÐ()á¥Ð

Is it possible to create $array1, array2, ... without using Assign() ?

Thank you for helping.

TaGaDa

Link to comment
Share on other sites

Learn to use higher dimensions in the arrays. This creates a single 2D array based on the user input number. Each 'thingy' gets 5 arrays created for it (a thru e, or actually 0 thru 4). Note that the 1D array is created as $avTemp and that array is stored as an element inside $avArrays:

#include <array.au3>

$n = Number(InputBox("Test", "How many thingys?", "0"))
Dim $avArrays[$n][5] ; 5 Subscripts for each thingy [$n][0] thru [$n][4]

For $x = 0 To UBound($avArrays) - 1
    For $y = 0 To UBound($avArrays, 2) - 1
        Dim $avTemp[1] = [0]
        _ArrayAdd($avTemp, "Add x=" & $x & " y=" & $y)
        _ArrayAdd($avTemp, "Update x=" & $x & " y=" & $y)
        $avArrays[$x][$y] = $avTemp
    Next
Next

MsgBox(64, "Status", "Created " & ($n * 5) & " arrays, five each for " & $n & " thingys.")

; Display the third array for the second thingy...
$avTemp = $avArrays[1][2] ; remember numbering is zero-based
_ArrayDisplay($avTemp, "2nd thingy, third array")

To access one of those arrays, first you copy it out of $avArrays to a temp variable. For example, the demo displays the contents of the third array of the second thingy ($c2 in your code).

:rolleyes:

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

I seem to understand. i did not know the UBound() function.

thank you for your code

I would not found this by myself.

:">

Assume the lotus position, calm your inner self, and chant with me...

...arrays are our friends, arrays are our friends, arrays...

:rolleyes:

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