Sign in to follow this  
Followers 0
tes5884

Understanding Arrays

13 posts in this topic

Hi Guys,

I'm having a hard time wrapping my brain around Arrays. Specifically, multi-dimensional, as well as dimension and entry limits.'

I already read the AutoIt docs page a couple of times.

Anyone have a better explanation and/or links?

Thanks!

Share this post


Link to post
Share on other sites



The wiki has a very good tutorial describing how arrays work.


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

tes5884,

I recommend the Arrays tutorial in the Wiki. Please post again if you still have questions. :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

x axis VS x + y axis VS x + y + z axis

Remember in geometry when you had to calculate distances in a 3 dimensional object? you had your x,y, and z axis. Same idea.

x = rows

y = columns

z = depth

Local $array[1] ; single dimension array with 1 element

Local $2D[1][2] ; two dimensional array with 2 indexes and 1 element in each index.
; i.e. $2D[0][0], $2D[0][1]

Local $3D[1][2][2] ; three dimensional array with 2 planes, 2 indexes on each plane, and 1 elements in each index
; i.e. $3D[0][0][0], $3D[0][1][0], $3D[0][0][1],  $3D[0][1][1]

Spoiler

“Hello, ladies, look at your man, now back to me, now back at your man, now back to me. Sadly, he isn’t me, but if he stopped using ladies scented body wash and switched to Old Spice, he could smell like he’s me. Look down, back up, where are you? You’re on a boat with the man your man could smell like. What’s in your hand, back at me. I have it, it’s an oyster with two tickets to that thing you love. Look again, the tickets are now diamonds. Anything is possible when your man smells like Old Spice and not a lady. I’m on a horse.”

 

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Looking at it one way, the number of dimensions is almost meaningless.

It's just another way of labelling the same variables or "mailboxes" that you're creating.

$aArray[24] is the same thing as $aArray[3][8] (3 x 8 = 24) which is the same thing as $aArray[3][2][4] (3 x 2 x 4 = 24).

They are all just a table of 24 variables.

If your 3-story apartment building has 24 units and you just want to store all the apartment numbers then use $aArray[24] (apt#).

If you want to organize them by floor you could create the same 24 boxes but reference them as $aArray[3][8] (floor/apt#)

If you had a reason to keep the apartments on the north side of the building separate from those on the south side, then you could setup your 24 mailboxes as $aArray[3][2][4] (floor/north-south/apt#)

When you reference the 17th element of the 1-dimension array; $aArray[17], it is the same thing internally as referencing element $aArray[2][0][1] of the 3-dimension array (2 x 8 + 0 x 4 + 1 x 1 = 17)

Hope I haven't made things worse ;)

Edit: You could simulate any number of dimensions using a 1-dimension array and a few lines of code. This is, at least conceptually, the same thing that goes on internally when you decide to split your array into different dimensions:

Global $aApartments[24] = ["1A","1B","1C","1D","1E","1F","1G","1H","2A","2B","2C","2D","2E","2F","2G","2H","3A","3B","3C","3D","3E","3F","3G","3H"]

MsgBox(0, "1-Dimension", Dimension_Simulator("24", "17")) ; get element [17] of $aArray[24]
MsgBox(0, "2-Dimension", Dimension_Simulator("3*8", "2|1")) ; get element [2][1] of $aArray[3][8]
MsgBox(0, "3-Dimension", Dimension_Simulator("3*2*4", "2|0|1")) ; get element [2][0][1] of $aArray[3][2][4]

Func Dimension_Simulator($structure, $element)
    Local $aStructure = StringSplit($structure, "*")
    Local $iSize = Execute($structure) ; total elements

    Local $aElement = StringSplit($element, "|")
    Local $iTarget
    For $x = 1 to $aElement[0] ; calculate element offset
        $iTarget += $aElement[$x] * ($iSize / $aStructure[$x])
     $iSize /= $aStructure[$x]
    Next
    Return $aApartments[$iTarget]
EndFunc
Edited by Spiff59
1 person likes this

Share this post


Link to post
Share on other sites

Alright, I have lot's of homework now :) I'll keep you guys posted. Thanks!!!

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

Question; if I have a variable

toast = $var[2][2]

Does that mean I can have values like the following;

$var[0][0]

$var[0][1]

$var[0][2]

$var[1][0]

$var[1][1]

$var[1][2]

$var[2][0]

$var[2][1]

$var[2][2]

or am I missing something?

Thanks!!!

Edited by tes5884

Share this post


Link to post
Share on other sites

Your list of array elements is correct.

Array elements always start with an index of 0. If you have an $array[7] the index goes from 0 to 6 (or "UBound($array, 1) - 1)".


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

Your list of array elements is correct.

Array elements always start with an index of 0. If you have an $array[7] the index goes from 0 to 6 (or "UBound($array, 1) - 1)".

Does index 0 hold a comparable value to any other number?

In other words, does the first index (0), point to an element just like any other index ? or is it any different.

Share this post


Link to post
Share on other sites

Depends on how the array was created. It's often referred to as "zero-based" or "one-based". Means the data starts in row 0 or row 1. If it starts in row 1 then row 0 contains the number of rows.

If it is a two dimensional array then $array[0][0] contains the number of rows and $array[0][1] contains the number of columns.

Check function StringSplit as an example. You can decide if the function returns a zero- or one-based array.

1 person likes this

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

It's just like any other index.

Many functions that return an array (_FileListToArray()) use the 0 index to hold specific information. In the case of _FileListToArray(), the 0 index holds the total file/folder count. For these functions you can iterate over them as follows:

For $i = 1 To $array[0]
    msgbox(0,"",$array[$i])
Next

For 0-based arrays, you can iterate over them as:

For $element in $array
    msgbox(0,"",$element)
Next

Spoiler

“Hello, ladies, look at your man, now back to me, now back at your man, now back to me. Sadly, he isn’t me, but if he stopped using ladies scented body wash and switched to Old Spice, he could smell like he’s me. Look down, back up, where are you? You’re on a boat with the man your man could smell like. What’s in your hand, back at me. I have it, it’s an oyster with two tickets to that thing you love. Look again, the tickets are now diamonds. Anything is possible when your man smells like Old Spice and not a lady. I’m on a horse.”

 

Share this post


Link to post
Share on other sites

#13 ·  Posted (edited)

Got it. Thanks water and mechaflash213.

Edited by tes5884

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

  • Similar Content

    • Eli_jahbot
      By Eli_jahbot
      My esteemed Autoits I need your help once again.
      I'm trying to figure out how to create a loop that gets 1 value from an array and repeats until each value from the array has been used. I have never used arrays before and I know once I learn more things should get easier for me. 
      Here is what Im trying to do:
      -Have an array of values that determine what application i log into. ex: app1, app2, app3, app4 etc.
      -Have a loop that repeats a process sequentially using each value in the array to finish the process for each app1, app2, app 3 and so forth. I have 30 apps that I need to update on a regular basis and getting this sorted out is what I perceive to be the best way to do it.
      Here is my feeble attempt that obviously fails:
      #include <msgboxconstants.au3>
      #include <Constants.au3>
      #include <array.au3>
      Login()
      Func Login()
          local $array[30] = ["10", "11", "12",etc etc]
          ;;Local $site = InputBox("ERx Site","What site do you want to login as?","","")
          Local $userid = InputBox("ERx Login", "What is your username?", "", "")
          Local $Passwd = InputBox("Security Check", "Enter your UAT password.", "", "*")
      for $1 = 1 to 30(I need to do the same steps in 30 different apps)
      run("Z:launch.exe")
      WinWaitActive("Input")
      Send (Sequential ARRAY VALUE HERE)
      Send("{ENTER}")
      WinWaitActive("window")
      Send($userid)
      Send("{TAB}")
      send($Passwd)
      Send("{ENTER}")
      WinWaitActive("[CLASS:SunAwtDialog]")
      Sleep(500)
      WinClose("Home Page")
      Next
      EndFunc
       
      your help is greatly appreciated.
      Thanks for your time
    • sree161
      By sree161
      Hi,
      i have a code which generates two numeric outputs.i have to save them in excel.
      Is there any way to export them to specific cells in excel???
    • TotalAuto
      By TotalAuto
      Howdy All
      I've gone around and around in circles wasting hours trying to fix this problem to no avail so I thought I would try posting for help given there are some real smart people in this forum.
      Background
      I have 5 separate .au3 scripts that all do different basic tasks. For example:
      1.au3 = opens Chrome browser to obtain information from a specific website then closes
      2.au3 = opens an Excel workbook to run a macro then saves and closes
      3.au3 = Open two seperate workbooks and transfers data from one to the other then saves and closes
      4.au3 = .......etc
      5.au3 = .......etc
      These 5 separate scripts, doing completely different tasks, need to each run once per day at 5 different designated times within a day and then close. For example:
      1.au3 = 10am
      2.au3 = 12pm
      3.au3 = 2pm
      4.au3 = 4pm
      5.au3 = 5pm
      Problem
      I can not get these different scripts to reliably run at their designated times. When I manually run these scripts individually by using 'Go F5' they work perfectly. If I convert these scripts to an .exe and manually run each one they work about 98% of time.
      How can I schedule these different .au3 files or associated .exe files to reliably run each day at different times?
      Attempts To Fix The Issue
      1. I have tried converting each .au3 script into their own .exe file and use Window's Task Scheduler to run these .exe files at their designated time but the success rate  of running each .exe in full, to completion, without error is very low at about 30%. Things that commonly go wrong include a browser not opening but movement still continues on the desk top. Other times things just do not happen at all.
      2. I have Windows 7 64 bit and have tried creating and running both (x86) and (x64) .exe files but again reliability problems exist;
      3. I have also tried moving each .exe file to the My Documents folder as I read someone that keeping your files on your desktop ties your files to individual Windows user profiles which can cause AutoIt operating errors. Not sure if this is correct but thought I would try it anyway. It did not fix my issue.
      4. I installed a program called AlwaysUp which supposedly always reliably runs in the background and will reliably execute your AutoIt script or .exe files. Still have significant reliability issues.
      Therefore, can someone please provide advice on how I can get my 5 different .au3 files to run at 5 designated times through the day, every day, without fail? Overtime I will be creating more and more different .au3 files to run certain tasks throughout the day and do not want to create one large AutoIt file that continually runs and attempts to do all the different tasks itself.
      Any help is very appreciated.
      Thanks
      Dan
       
       
    • hugomito
      By hugomito
      Hi all,
      I built an AutoIt application that interacts with several other applications/software. Now, it's turn to interfact with Visual Studio Team Services (VSTS).
      Does anyone has a blog, demo, script to share?
      Thanks!
    • Viki
      By Viki
      This is my first time here so please dont bombard me that what a silly question I am asking!!
      I have 500 rows (A1:A500) in a spreadsheet and I just want to copy one by one row and then paste into another application and then press enter, loop should repeat this until finishes all 500 rows.
      I have looked at clipget(), clip(put() but dont know how to select next row in next turn. I also looked at Array to store but again no luck. Can some guide me please..