Jump to content
Sign in to follow this  
Abdulla060

adding elements to 3d arrays

Recommended Posts

Abdulla060

i have a 3d array that is [10][20][6] for now lets assume that its [3][3][3] so it looks something like this 

[[[1,2,3],[1,2,3],[1,2,3]],
 [[1,2,3],[1,2,3],[1,2,3]],
 [[1,2,3],[1,2,3],[1,2,3]]]

i need to add another 1d  array to the position [2][3] ( i hope its clear) so it becomes like this 

[[[1,2,3],[1,2,3],[1,2,3]],
 [[1,2,3],[1,2,3],[1,2,3]],
 [[1,2,3],[1,2,3],[1,2,3],[4,5,6]]]

and i have no idea how :) 

Share this post


Link to post
Share on other sites
TheXman
Posted (edited)

The first thing you would need to do is redim the array because it would no longer fit in a [3][3][3] array.  It would have to be at least [3][4][3].

[
    [
        [1,2,3],
        [1,2,3],
        [1,2,3]
    ],
    [
        [1,2,3],
        [1,2,3],
        [1,2,3]
    ],
    [
        [1,2,3],
        [1,2,3],
        [1,2,3],
        [4,5,6]
    ]
 ]

 

Edited by TheXman
Corrected typo in array structure

Whoever said that there's no such thing as a dumb question, probably asked a lot of DUMB questions.  Dumb questions are ones that you can easily find the answer to on your own.

Share this post


Link to post
Share on other sites
TheXman
Posted (edited)
#include <Array.au3>

example()

;==========================================================================
;
;==========================================================================
Func example()

    Local $aArray[3][3][3] = _
        [ _
            [ _
                [1,2,3], _
                [1,2,3], _
                [1,2,3] _
            ], _
            [ _
                [1,2,3], _
                [1,2,3], _
                [1,2,3] _
            ], _
            [ _
                [1,2,3], _
                [1,2,3], _
                [1,2,3] _
            ] _
         ]

    ; Increase the 2nd dimension
    ReDim $aArray[3][4][3]

    ; Add [4,5,6] to [2][3]
    $aArray[2][3][0] = 4
    $aArray[2][3][1] = 5
    $aArray[2][3][2] = 6

    ; Show that [4,5,6] was  successfully added to [2][3]
    Local $aTemp[0]
    _ArrayAdd($aTemp, $aArray[2][3][0])
    _ArrayAdd($aTemp, $aArray[2][3][1])
    _ArrayAdd($aTemp, $aArray[2][3][2])
    _ArrayDisplay($atemp)

EndFunc

 

Edited by TheXman
Fixed a typo

Whoever said that there's no such thing as a dumb question, probably asked a lot of DUMB questions.  Dumb questions are ones that you can easily find the answer to on your own.

Share this post


Link to post
Share on other sites
Abdulla060
Posted (edited)

thank you very much for your reply but i decided to just turn the last level of arrays into strings so i ended with a 2d array which is much easier to work with, however now i have a new question how do append data to to each column in a [3][3] array if i use the _arrayadd it will add the data to to the right columns but it will create a new row for each new value

Edited by Abdulla060
changed the question

Share this post


Link to post
Share on other sites
TheXman
Posted (edited)

.

Edited by TheXman
Question was changed so answer was to a different question

Whoever said that there's no such thing as a dumb question, probably asked a lot of DUMB questions.  Dumb questions are ones that you can easily find the answer to on your own.

Share this post


Link to post
Share on other sites
TheXman
Posted (edited)

 .

Edited by TheXman
Question was changed so answer was to a different question

Whoever said that there's no such thing as a dumb question, probably asked a lot of DUMB questions.  Dumb questions are ones that you can easily find the answer to on your own.

Share this post


Link to post
Share on other sites
Abdulla060
8 minutes ago, TheXman said:
#include <Array.au3>

example1()

Func example1()

    Local $aArray[3][3] = [ [1,1,1], [1,0,0], [1,0,0] ]

    _ArrayDisplay($aArray, "Example1")

EndFunc

 

ok that was a dump question from my end xD sorry about that 

now one last thing and everything is clear for me. how do i append data to a column (without selecting the row basically add data to the first empty cell in a column)

Share this post


Link to post
Share on other sites
TheXman

Maybe it would be easier if I had a better understanding of what you are trying to achieve because your question, as it relates to arrays, does not make much sense to me.  Adding rows is much more common than dynamically adding columns.  It is easy enough to do but I think there's probably a better solution.


Whoever said that there's no such thing as a dumb question, probably asked a lot of DUMB questions.  Dumb questions are ones that you can easily find the answer to on your own.

Share this post


Link to post
Share on other sites
Abdulla060
39 minutes ago, TheXman said:

Maybe it would be easier if I had a better understanding of what you are trying to achieve because your question, as it relates to arrays, does not make much sense to me.  Adding rows is much more common than dynamically adding columns.  It is easy enough to do but I think there's probably a better solution.

i have a script that pulls data from a json file and add them to the 3d array from earlier (which is now 2d) im just trying to keep everything in one array rather than defining 10 of them, i want to put the data into each array and make the first element of each array an index of how many things are in each array 

local $array1[3] = [3 ,'a', 'b', 'c']
local $array2[3] = [3 ,'a', 'b', 'c']
Local $array3[3] = [3 ,'a', 'b', 'c']
Local $allarrays[3] = [$array1, $array2, $array3]

what i want is this but using a single 2d array

Share this post


Link to post
Share on other sites
TheXman

Why move the data from JSON into an array?  The JSON data can, most likely, be processed just as easily in its native format as it can be in an array.  It it sounds like it would be much more efficient to process it as JSON since there are already methods/functions to give you the counts of JSON objects and JSON array items.

 


Whoever said that there's no such thing as a dumb question, probably asked a lot of DUMB questions.  Dumb questions are ones that you can easily find the answer to on your own.

Share this post


Link to post
Share on other sites
Abdulla060

because i need to edit that data and sort them before i can use it, if not for that then yes using it from the json file would be much more efficient

Share this post


Link to post
Share on other sites
Abdulla060

i give up i'm just going to make 10 arrays :(

Share this post


Link to post
Share on other sites
iamtheky
Posted (edited)

if you have the entire string you can just declare it in a 2D fashion

#include<array.au3>

local $array = [[3 ,'a', 'b', 'c'],[6 ,'a', 'b', 'c','d','e','f'],[4 ,'a', 'b', 'c','d']]

_ArrayDisplay($array)

also, i would add things to it with something like this:

#include<array.au3>

local $array = [[3 ,'a', 'b', 'c'],[6 ,'a', 'b', 'c','d','e','f'],[4 ,'a', 'b', 'c','d']]
_ArrayDisplay($array , 'base')

local $aAdd = [7 ,'a', 'b', 'c','d','e','f','g']

If ubound($aAdd) > ubound($array , 2) Then ReDim $array[ubound($array)][ubound($aAdd)]

_ArrayAdd($array , _ArrayToString($aAdd) , 0 , "|")
_ArrayDisplay($array)

 

Edited by iamtheky

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

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  

  • Similar Content

    • AnonymousX
      By AnonymousX
      Hello,
      I'm trying to write a script that moves copies excel cells into an array. I'll than manipulate the values and send array into another program. 
      I don't want range to be specific to a workbook, or sheet, or set of cells.
      I want user to be able to highlight desired cells and to copy either normally ("Ctrl+C") or by a hotkey ("Alt+C"). 
      Could someone help me with this?
      Thank you,
      I've tried to write the framework:
      #include <Array.au3> #include <Excel.au3> #include <MsgBoxConstants.au3> HotKeySet("!v", "Pastedata") func Makearray() local $bArray() 'User has cells already copied 'Convert clipboard into an array 'I don't know how excel stores data to clipboard so don't know how to bring it into array _Arraydisplay($bArray) return $bArray end func func Pastedata() Local aArray 'make array based on assumption user has already copied a range to clipboard aArray = Makearray() 'paste code 'don't worry about this I got the rest end func  
    • RamDemon
      By RamDemon
      Hi,
      Did anyone tried to  use Redis  with AutoIT as store DB ?
       Redis <-- more about it
      Mladen
    • nooneclose
      By nooneclose
      Hey. I'm working on a new project and was wondering if there is a better way to "update" my Column E array. 
      Here is my code: 
      Local $nI  = 0                                                            ;Creates a name index of 0: nI = Name index Local $nII = 1                                                            ;Creates a name index of 1 for second loop: nII = Name Index 2 For    $iN = 0 To $IndexRows Step 1                                       ;Checks the roster for any names that appear twice      For $iN2 = 0 To $IndexRows Step 1          if $d_Names[$nI] == $d_Names[$nII] And $d_Names[$nII] <> "" Then              Local $timeSheetName = _ArraySearch($e_Names, $d_Names[$nI], 0, 0, 0, 0, 1)              ;MsgBox($MB_SYSTEMMODAL, "Found it", $d_Names[$nI] & " In column E on Row " & $timeSheetName)              Local $eI  = $timeSheetName + 1              ;ConsoleWrite($timeSheetName & @CRLF)              ;ConsoleWrite($eI & @CRLF)              ;ConsoleWrite(@CRLF)              _Excel_RangeInsert($OpenWorkbook.ActiveSheet, "E" & $eI & ":F" & $eI, $xlShiftDown)                                                                          ;Inserts a empty cell in columns E and F.              _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $d_Names[$nII], "E" & $eI)                                                                         ;Fills the empty cell in columns E with the doubled name              $aArray_Index = 2                                           ;Array element counter              For $Index = 2 To $IndexRows Step 1                        ;Loops through every row in the Excel file unto no rows are found or a null row is found                  $Array_Value_E = _Excel_RangeRead($OpenWorkbook, Default, "E"&$Index)                  $e_names[$aArray_Index] = $Array_Value_E                ;While the code loops every value in column E is stored in the E array (updating the array)                  $aArray_Index += 1              Next              ExitLoop          EndIf      Next      $nI  += 1      $nII += 1 Next Basically, It checks a roster for people whose name appears twice then inserts a new "row" for that person because they work in two different departments.
      I have to find that name however in Column E if two appear in column D. My code works but I think it is not as efficient as it could be. 
      Any ideas on how to improve the "update" for my array?
      (once it finds the double names in Column D it then searches for that name by going name by name in the Column E array and once it finds it inserts a new row. However, the E array doesn't have that new row stored in it so I have to "update" the array to properly find the next name)
      Any and all tips would be greatly appreciated. 
       
      NOTE: Just assume I'm opening the excel file properly please do not add that code in, it only complicates your answer. 
    • Miliardsto
      By Miliardsto
      Hello Im wondering if using this https://ohtejera.github.io/ImperiusAutoIt/#started
      UDF can i make that I can control my windows application with phone?
      like for example click button Start on android phone and then something would be done in my windows app?
    • nooneclose
      By nooneclose
      How do I properly convert this to Autoit? This is a VBA macro that I recorded in Excel.
       ActiveSheet.Outline.ShowLevels RowLevels:=2 I need this to close my subtotal once it is finished. 
      any help will be greatly appreciated. 
×