Jump to content

Array within an array


 Share

Go to solution Solved by Melba23,

Recommended Posts

Hi

How can I put an array within an array? Found >this UDF, but did not understand how to use it.

Basically I have 2 columns (List of hotkeys)(ArrayHotkeyInfo) (look in the picture) in main array, Every hotkey has additional information. For example a list of windows associated with that key, this why I can not make one array.

I made an example, run it & see that F1 was added into an array. But how to add an array into the second column of th emain array and how to call data from that sub array?

With regards.

 

thumb_array%20within%20an%20array.png

#Include <Array.au3>

Global $ArHotkeys[1][2]
global $ArHotkeyInfo[1][3]

_HotKeySet("{F1}", "Mozilla Firefox", 1, "Enabled")
_ArrayDisplay($ArHotkeys, "$ar_hotkeys")

Func _HotKeySet($HOTKEY, $WINDOW, $WinTitleMatchMode, $ENABLED_DISABLED_STATE)
    $hotkeypos = _check_if_hotkeyexists($HOTKEY)
    if $hotkeypos <> 0 Then
        ConsoleWrite($hotkeypos& @LF)
    Else
        _add_key($HOTKEY)
    EndIf
EndFunc
#cs --------------------------------------------------
;## Check if a hotkey exists if yes return its position
#ce --------------------------------------------------
func _check_if_hotkeyexists($HOTKEY)
    for $i = 0 to UBound($ArHotkeys) -1
        if $ArHotkeys[$i][0] = $HOTKEY Then return $i
    Next
    return 0
EndFunc
#cs --------------------------------------------------
;## Adds a hotkey
#ce --------------------------------------------------
func _add_key($HOTKEY)
    $iRow = UBound($ArHotkeys)  ;get Rows
    $iCol = UBound($ArHotkeys, 2)   ;get Columns

    ReDim $ArHotkeys[$iRow + 1][$iCol]  ; add more rows +1
    $ArHotkeys[$iRow][0] = $HOTKEY
EndFunc
My Projects:[list][*]Guide - ytube step by step tut for reading memory with autoitscript + samples[*]WinHide - tool to show hide windows, Skinned With GDI+[*]Virtualdub batch job list maker - Batch Process all files with same settings[*]Exp calc - Exp calculator for online games[*]Automated Microsoft SQL Server 2000 installer[*]Image sorter helper for IrfanView - 1 click opens img & move ur mouse to close opened img[/list]
Link to comment
Share on other sites

Yes, you can, however its clunky to use.  I'm Dev'ing a medium sized program, and initially I thought an array inside of an array was my best solution, since it "looked better"

#include <array.au3>
 
Local $arr[2]
 
$arr[0] = "test"
$arr[1] = stringsplit("test array value 1|test array value 2","|")
_ArrayDisplay($arr[1])  ;this succeeds, but how do I access the data?
 

 

However, you cannot access that data without first assigning a temp variable:

#include <array.au3>
 
Local $arr[2]
 
$arr[0] = "test"
$arr[1] = stringsplit("test array value 1|test array value 2","|")
 
Local $temp = $arr[1]
 
_ArrayDisplay($temp)
msgbox(0,'',$temp[1])
 

 

In the end, it makes your code more hard to compartmentalize, as well as error check (in ideal code, you would IsArray($temp) every time before acting on the variables.).  I just spent a couple hours re-writing all of my sort/computations of my data from array of arrays to a 2d array and I feel much better about it.

Edited by kaisies
Link to comment
Share on other sites

  • Moderators
  • Solution

kaisies,

 

However, you cannot access that data without first assigning a temp variable

Oh yes you can - since 3.3.10.0 released in December 2013! ;)

#include <MsgBoxConstants.au3>

Local $aInner[3] = ["A", "B", "C"]

Local $aOuter[1] = [$aInner]

$sElement = ($aOuter[0])[1] ; Note syntax!!!!

MsgBox($MB_SYSTEMMODAL, "Inner element", $sElement)
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

This is wery nice, works, but how do you get the size of that inner array? See the example.

I cant just call ubound on the inner array because I plan to generate an aray for each hotkey.

Local $aOuter[1][2]
Local $aInner[1][3]

$aInner[0][0] = 'a'
$aInner[0][1] = 'b'
$aInner[0][2] = 'c'

$aOuter[0][1] = $aInner

ConsoleWrite(ubound(($aOuter[0][1])) & @CRLF) ;; does not work

for $i = 0 to 100
    ConsoleWrite(($aOuter[0][1])[0][$i] & @CRLF)
    if @error then ExitLoop                         ; does not work
Next

ConsoleWrite('->' & ($aOuter[0][1])[0][0] & @CRLF)
Edited by goldenix
My Projects:[list][*]Guide - ytube step by step tut for reading memory with autoitscript + samples[*]WinHide - tool to show hide windows, Skinned With GDI+[*]Virtualdub batch job list maker - Batch Process all files with same settings[*]Exp calc - Exp calculator for online games[*]Automated Microsoft SQL Server 2000 installer[*]Image sorter helper for IrfanView - 1 click opens img & move ur mouse to close opened img[/list]
Link to comment
Share on other sites

ConsoleWrite(ubound(($aOuter[0][1])) & @CRLF) ;; does not work

To me it say it return 1 (and that is correct result if you ask me).

If you're looking for columns instead of rows please open your help file and read UBound and its second parametar 'Dimension'.

PS: if you did not understand what im saying then _ArrayDisplay is your best frend  ;)

Edited by bogQ

TCP server and client - Learning about TCP servers and clients connection
Au3 oIrrlicht - Irrlicht project
Au3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related)



460px-Thief-4-temp-banner.jpg
There are those that believe that the perfect heist lies in the preparation.
Some say that it’s all in the timing, seizing the right opportunity. Others even say it’s the ability to leave no trace behind, be a ghost.

 
Link to comment
Share on other sites

ConsoleWrite(ubound(($aOuter[0][1])) & @CRLF) ;; does not work

To me it say it return 1 (and that is correct result if you ask me).

Ahh of course, it works, I just made 1. row in the sub array, this why it returns 1, my bad,

Thank you. :)

My Projects:[list][*]Guide - ytube step by step tut for reading memory with autoitscript + samples[*]WinHide - tool to show hide windows, Skinned With GDI+[*]Virtualdub batch job list maker - Batch Process all files with same settings[*]Exp calc - Exp calculator for online games[*]Automated Microsoft SQL Server 2000 installer[*]Image sorter helper for IrfanView - 1 click opens img & move ur mouse to close opened img[/list]
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...