# Array Stuff

## Recommended Posts

Hey Guys...

I have been using AutoIt for 1 week now. It's a great tool but I couldn't manage Arrays.

I am trying to allocate to an array (which it's length will be randomly determined) a Random number and after that to read it or display it on a MsgBox.

Here is what I have done so far...

```\$arrayLength=(1,20); will determine the array dimention
For \$loop=1 to \$arrayLength
\$myRandNumber=Random (0,9)
; here I should pusd 'myRandNumber' to the array
Next
Msgbox (0,"",?); Here all my array elements should be displayed```

Thanks for the help!

##### Share on other sites

Try the following:

```\$arrayLength=20;
Dim \$array[\$arrayLength]
For \$loop=0 to \$arrayLength-1
\$myRandNumber=Random (0,9)
\$array[\$loop] = \$myRandNumber
Next
\$string = ""
For \$loop=0 to \$arrayLength - 1
\$string = \$string & \$array[\$loop] & " "
Next
Msgbox (0,"",\$string); Here all my array elements should be displayed```

Notes:

1. Not quite sure what you where trying to do with the \$arrayLength=(1,20); statement. It isn't legal as is. I've replaced it with a single value

2. The loops go from 0 to \$arrayLength - 1 because AutoIt arrays start at zero

3. AFAIK there is no statement to print out an array directly. I've added a loop to concatonate the array elements into a string for output

4. If you don't need \$myRandNumber for any thing then you can simply assign directly to the array element (i.e. \$array[\$loop] = Random(0,9) )

GrahamS

##### Share on other sites

Thanx GrahamS, I got it.

I have another little question. The following returned an error. Why?

```Dim \$myArray [3]
For \$loop=0 to 3
\$myRandNumber=Random (1,9)
\$myArray [\$loop] = \$myRandNumber
Next```

10x again...

##### Share on other sites

• Developers

Thanx GrahamS, I got it.

I have another little question.   The following returned an error. Why?

```Dim \$myArray [3]
For \$loop=0 to 3
\$myRandNumber=Random (1,9)
\$myArray [\$loop] = \$myRandNumber
Next```

10x again...

Thats because from 0 to 3 is 4 steps.... Edited by JdeB

Live for the present,
Dream of the future,
Learn from the past.

##### Share on other sites

As usual, :iamstupid:

##### Share on other sites

• Developers

As usual,  :iamstupid:

nee.... just every now and then you ... thats all..

Live for the present,
Dream of the future,
Learn from the past.

## Create an account

Register a new account

• ### Recently Browsing   0 members

×

• Wiki

• Back

• #### Beta

• Git
• FAQ
×
• Create New...