Jump to content

Array help needed


ddarek
 Share

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
Link to comment
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 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

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
Link to comment
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 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
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 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

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