Jump to content

Help! How to set value to array which presented as string


hunt
 Share

Recommended Posts

Hello all. I can't to solve problem with assigning values to 2-dimensional arrays.

Dim $List1[10][10]

Dim $List2[10][10]

Dim $List3[10][10]

Dim $List4[10][10]

...

$n=10

For $i=1 to $n

"$List" & $i & "[0][0]"=10 ;?????????????

Next

Link to comment
Share on other sites

Hello all. I can't to solve problem with assigning values to 2-dimensional arrays.

Dim $List1[10][10]

Dim $List2[10][10]

Dim $List3[10][10]

Dim $List4[10][10]

...

$n=10

For $i=1 to $n

"$List" & $i & "[0][0]"=10 ;?????????????

Next

If you don't say what you want to do...

I think that you want this

For $INDEX = 0 To 9
    Dim $LIST[$INDEX][10][10]
Next

For $I = 0 To 9
    $LIST[$I][0][0] = "10"
Next

When the words fail... music speaks.

Link to comment
Share on other sites

I think he may want to look at Assign() in the help file

[edit]

Nevermind.. assign does not work with arrays

Edited by SpookMeister

[u]Helpful tips:[/u]If you want better answers to your questions, take the time to reproduce your issue in a small "stand alone" example script whenever possible. Also, make sure you tell us 1) what you tried, 2) what you expected to happen, and 3) what happened instead.[u]Useful links:[/u]BrettF's update to LxP's "How to AutoIt" pdfValuater's Autoit 1-2-3 Download page for the latest versions of Autoit and SciTE[quote]<glyph> For example - if you came in here asking "how do I use a jackhammer" we might ask "why do you need to use a jackhammer"<glyph> If the answer to the latter question is "to knock my grandmother's head off to let out the evil spirits that gave her cancer", then maybe the problem is actually unrelated to jackhammers[/quote]

Link to comment
Share on other sites

Hello all. I can't to solve problem with assigning values to 2-dimensional arrays.

Dim $List1[10][10]

Dim $List2[10][10]

Dim $List3[10][10]

Dim $List4[10][10]

...

$n=10

For $i=1 to $n

"$List" & $i & "[0][0]"=10 ;?????????????

Next

AutoIt has functions to work variable names specified by variable strings: Assign() and Eval()

But they don't work with array syntax. They will work with an array variable, but only where the entire variable is being used, not where any indexes must be supplied.

This demo uses Assign() to create five array variables. The array properties cannot be applied with Assign(), but come from the returned array provided by _ArrayDataGen(). Where the array must be used ByRef, as in _ArrayDisplay(), it must first be copied to a statically named temp variable:

#include <Array.au3>

Global $iData = 0, $avArray

For $n = 1 To 5
    Assign("Var" & $n, _ArrayDataGen(), 2)
Next

Func _ArrayDataGen()
    Local $avTemp[5][5]
    For $r = 0 To 4
        For $c = 0 To 4
            $avTemp[$r][$c] = $iData
            $iData += 1
        Next
    Next
    Return $avTemp
EndFunc

For $n = 1 To 5
    $avArray = Eval("Var" & $n)
    _ArrayDisplay($avArray, "$Var" & $n)
Next

Needless to say, there can only be very rare and esoteric reasons to put this kind of complexity in your scripts. You are probably missing an easier path.

Besides... Assign/Eval are evil!

:)

P.S. On the assumption that you want the row count in [0][0], this might do about what you want, anyway:

#include <Array.au3>

$n=10; number of rows to declare
Dim $List1[$n + 1][10] = [[$n]]; Sets count in [0][0] to $n
Dim $List2[$n + 1][10] = [[$n]]
Dim $List3[$n + 1][10] = [[$n]]
Dim $List4[$n + 1][10] = [[$n]]

_ArrayDisplay($List1, "$List1")

:)

Edited by PsaltyDS
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

PsaltyDS

Thanks for example. I tried it later so i dont' know as to apply this example for my script.

What are you trying to do? The Assign/Eval code I posted was for academic interest. If you just want the count in [0][0], then use the code I posted in the P.S.

Andreik showed how to put your data into a single 3D array.

You can also nest arrays (put an entire array in as a single element in another array).

What works best depends on what you need to do, so what are you trying to do?

:)

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