Sign in to follow this  
Followers 0
ddarek

Array help needed

6 posts in this topic

#1 ·  Posted (edited)

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 this post


Link to post
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 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Hi THnx for help

"fill $los with your data"

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 this post


Link to post
Share on other sites

#4 ·  Posted (edited)

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 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
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 this post


Link to post
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 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
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
Sign in to follow this  
Followers 0