Jump to content

Array getting subarray


Recommended Posts

Hello. I'm just learning Python at school but I like to use AutoIt also, I can't get past one thing though.
Lets say I have some information about chars and their ASCII value but I don't have it sorted. The idea is that information about every char is stored in its own subarray. How can I extract the value of lets say char 2 which should return something like this?

["a", 97]


As in python you just write array[1] and it returns the second subarray, but how do you do this in AutoIt? Thanks!

$array = [["b", 98], ["a", 97], ["c", 99]]

I already read some topics about this but the solutions seemed very complicated but there should be an easy solution for this as this is a basic operation (I suppose)

Edited by knuxfighter
Link to comment
Share on other sites

  • Moderators

knuxfighter,

It is not that difficult:

#include <Array.au3>

Global $aArray2D[][] = [["b", 98], ["a", 97], ["c", 99]]

; Extract the data for element [1]
$aExtract = _ArrayExtract($aArray2D, 1, 1)

_ArrayDisplay($aExtract, "", Default, 8)

Please ask if you have any questions.

M23

Edited by Melba23
27k

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
Share on other sites

4 minutes ago, Melba23 said:

knuxfighter,

It is not that difficult:

#include <Array.au3>

Global $aArray2D[][] = [["b", 98], ["a", 97], ["c", 99]]

; Extract the data for element [1]
$aExtract = _ArrayExtract($aArray2D, 1, 1)

_ArrayDisplay($aExtract, "", Default, 8)

Please ask if you have any questions.

M23

Thank you. I have one more question. How do I add ["d", 100] to the end of the array? Probably I have to resize the array to size+1 as none of the following seem to work:

$aArray2D[3][0] = "d"
$aArray2D[3][1] = 100

$aArray2D[3] = ["d", 100]

_ArrayAdd($aArray2D, ["d", 100])

_ArrayAdd($aArray2D[3][0], "d")
_ArrayAdd($aArray2D[3][1], 100)



Or is there any simpler solution? Thank you again :)

Link to comment
Share on other sites

  • Moderators

knuxfighter,

#include <Array.au3>

Global $aArray2D[][] = [["b", 98], ["a", 97], ["c", 99]]

_ArrayAdd($aArray2D, "d|100")

_ArrayDisplay($aArray2D, "", Default, 8)

Look in the remarks section of the help file page for _ArrayAdd to see the correct syntax for adding elements to arrays.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

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

×
×
  • Create New...