# Array help needed

## Recommended Posts

Hi

I am beginner in Autoit as well as in programming

Simple scripts I can write by declaring everything by steps

Recently I found ARRAYS.

Idea seems to me understandable but coding it - hmmm different story

I got case to be solved

Got pool with numbers 1-10

So

```Local \$los[10]
For \$x=0 To 9 Step +1
\$los[\$x]=Random(1,10,1)
Next```

I got my first array

Bad for me each element from my array got 3 features

- color

- shape

- weight

So I assume my new array is a below

```Local \$color = Random(1,4,1)
Local \$shape = Random(1,4,1)
Local \$weight = Random(1,4,1)

Local \$los[10][3]```

OK so in return I would have 10x [\$color, \$shape, \$weight]

But in many occasions features will be identical

I would like to have an output

"

You find eg: 10 elements = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

You got only this xxxxx color (and maybe xxxxx color, up to max 4 colors (whenever color is duplicated do not inform))

You goit only this xxxxxx shape (and maybe this xxxxx shape, up to max 4 shapes (whenever shape is duplicated do not inform))

Your elements weight are as follows eg elements = [1,4,3,4,1,2,3,4,3,4]

How to code it ?

Edited by ddarek

##### Share on other sites

You could use _ArraySort. Sort on a column (color, shape, weight). Then run through the array and only output thos columns where the value is different to the previous value.

```Local \$los[10][3]
; fill \$los with your data
; ...
; sort the array on column 1 (shape)
_ArraySort(\$los, 0, 0, 0, 1)
\$previous = ""
For \$i = 0 to UBound(\$los)
If \$los[\$i][1] <> \$previous Then
ConsoleWrite("Shape " & \$los[\$i][1])
\$previous = \$los[\$i][1]
EndIf
Next```

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2020-10-10 - Version 1.5.2.1) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2020-06-30 - Version 1.6.2.0) - Download - General Help & Support - Example Scripts - Wiki
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki, WebDriver - Wiki

##### Share on other sites

Hi THnx for help

how to fill 2D array ?

First problem

like ?

```Local \$color = Random(1,4,1)
Local \$shape = Random(1,4,1)
Local \$weight = Random(1,4,1)
Local \$los[10][3]
For \$x=0 To 9 Step +1
\$los[\$x][0]=\$color
\$los[\$x][1]=\$shape
\$los[\$x][2]=\$weight
Next```

Is it correct ?

Edited by ddarek

##### Share on other sites

Move Random into the loop. Else you just get identical values.

If you don't use your code in a function you should define variables using Global.

```Global \$los[10][3]
For \$x=0 To 9
\$los[\$x][0]=Random(1,4,1)
\$los[\$x][1]=Random(1,4,1)
\$los[\$x][2]=Random(1,4,1)
Next```
Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2020-10-10 - Version 1.5.2.1) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2020-06-30 - Version 1.6.2.0) - Download - General Help & Support - Example Scripts - Wiki
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki, WebDriver - Wiki

##### Share on other sites

Thnx for help

I dont know why but

For \$i = 0 to UBound(\$los) doesnt work but

For \$i = 0 to UBound(\$los,0) works fine

Now I can get what I wanted

##### Share on other sites

According to the help file parameter 2 stands for the dimension:

"Which dimension of a multi-dimensioned array to report the size of. Default is 1, which is the first dimension. If this parameter is 0, the number of subscripts in the array is returned."

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2020-10-10 - Version 1.5.2.1) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2020-06-30 - Version 1.6.2.0) - Download - General Help & Support - Example Scripts - Wiki
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki, WebDriver - Wiki

## Create an account

Register a new account

• ### Recently Browsing   0 members

×

• Wiki

• Back

• #### Beta

• Git
• FAQ
• Our Picks
×
• Create New...