Jump to content

Create array in a loopü


Recommended Posts

#include <Array.au3>
While 1

Local $arr[10]
_ArrayDisplay ($arr)
for $x=0 to 9
    $z=""
    for $y=0 to 10
        $z=$z & chr(Random(32,64))
    Next
    $arr[$x]=$z & $x
Next

_ArrayDisplay ($arr)
WEnd

That should do it ...

additionally you can empty the array with $arr="" after the next

Edited by Dan_555

Some of my script sourcecode

Link to comment
Share on other sites

Local $array[0] creates an empty 1D array (zero rows).

Local $array[0][3] creates an empty 2D array (zero rows of 3 columns).

And so on...

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

Ok maybe i messed up the question.

I know how i create an array. But i want create a completly new array in each loop. 

So for example If $value=3 i loop it 3 Times and get $array1, $array2, and $array3

But If my $value=5 i get $array1, $array2, $array3, $array4 and $array5

 

 

Link to comment
Share on other sites

Hi @TomJohn. :)

Something like this?

For $i = 1 to 3
    Dim $aArray[0]
    Assign("array"&$i, $aArray)
Next

ConsoleWrite(VarGetType($array1)&@CRLF)
ConsoleWrite(VarGetType($array2)&@CRLF)
ConsoleWrite(VarGetType($array3)&@CRLF)

 

Link to comment
Share on other sites

Bravo genius257, I like the way you scripted it (the Dim $aArray[0] should be placed before the loop but that's minor) . Imho, your script could find its place in the help file examples, topic Assign. The help file stipulates :

Assign ( "varname", "data" [, flag = 0] )
varname : The name of the variable you wish to assign. Cannot be an array element [...]

You showed the way to assign it to an array variable name, great :thumbsup:

Edited by pixelsearch
nothing important
Link to comment
Share on other sites

Hi @pixelsearch :).

Many thanks for the nice words :)

You are right about the dim within the loop, my bad :P

Just for fun, it is possible with some trickery to assign values to an array element:

#include <Array.au3>
#include <AutoItConstants.au3>

UnknwonVaribleName()
AssignExample('x')
AssignExample('y')

Func UnknwonVaribleName()
    Local Static $sName = "aArray"&Random(0, 200, 1)

    If IsDeclared($sName) Then Return $sName
    Local $aArray = [3, 2, 1]
    Assign($sName, $aArray, $ASSIGN_FORCEGLOBAL)
EndFunc

Func AssignExample($vValue)
    Local $sName = UnknwonVaribleName()
    _ArrayDisplay(Eval($sName), "before")
    Assign($sName, ArrayAssign(Eval($sName), $vValue, 1))
    _ArrayDisplay(Eval($sName), "after")
EndFunc

Func ArrayAssign(ByRef $aArray, $vValue, $iIndex1, $iIndex2 = 0, $iIndex3 = 0, $iIndex4 = 0)
    Switch @NumParams - 2
        Case 1
            $aArray[$iIndex1] = $vValue
        Case 2
            $aArray[$iIndex1][$iIndex2] = $vValue
        Case 3
            $aArray[$iIndex1][$iIndex2][$iIndex3] = $vValue
        Case 4
            $aArray[$iIndex1][$iIndex2][$iIndex3][$iIndex4] = $vValue
    EndSwitch
    Return $aArray
EndFunc

Now i don't see a good reason to ever do stuff like this, but it is fun to play with restrictions.

Edited by genius257
typo
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...