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

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

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

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

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.

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.

 

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

    • nooneclose
      By nooneclose
      Good afternoon, I am in need of some help. I am sure this is a stupid question requiring only one or two lines of code. However, I would greatly appreciate the help I cannot figure this out. I also tried searching for the answer on the internet but no one except me apparently seems to be having a hard time figuring this out and or is asking about it. 
      I simply want to change the "status" of an email from unread to read once I have processed it. My code is over 500 lines and I would like not to clutter this post with it. Assume I have all my includes and connections properly defined and stuff. 
      Here is the bit of code where I am trying to change the email that was used from unread to read:
      Func ChangeEmailStatus() ;******************************************************************************* ; changes the status of an email from unread to Read ;******************************************************************************* Local $iRows = UBound($aItems, $UBOUND_ROWS) MsgBox("", "Number of Unread emails (Before Change)", $iRows) _OL_ItemModify($oOutlook,$aItems[$i][0], Default, "Read=True") MsgBox("", "Array Display 1", $aItems[1][0]) MsgBox("", "Array Display 2", $aItems[2][0]) Local $iRows = UBound($aItems, $UBOUND_ROWS) MsgBox("", "Number of Unread emails (After Change)", $iRows) EndFunc  
    • SharpDressedMan
      By SharpDressedMan
      Hello,
      Is there any way to check for validity of a pointer to a DllStruct ?
      In the above code, a DllStruct is created from an invalid pointer. How to prevent from doing this ?
      local $tStruct = DllStructCreate("int i") DllStructSetData($tStruct, "i", 123) local $pStruct = DllStructGetPtr($tStruct) $tStruct = 0 ; destroy DllStruct ==> $pStruct becomes invalid ; how to check here for validity of $pStruct and prevent from doing the following ? $tStruct = DllStructCreate("int i", $pStruct) ; create DllStruct from invalid pointer... MsgBox(0, @ScriptName, @error) ; displays '0' : invalid pointer is not detected by DllStructCreate() MsgBox(0, @ScriptName, IsDllStruct($tStruct)) ; displays '1' : tStruct is assumed as a valid DllStruct object, which is not Thanks for help
    • nooneclose
      By nooneclose
      I need to send a string of text to this popup and click on the ok button to save it.
      Here is the code I have so far:
      ;Start IE Sleep(7000) $oIE = _IECreate("http://www.google.com") Sleep(500) _IELoadWait($oIE) $hIE = _IEPropertyGet($oIE, "hwnd") ; Get Handle of the IE window Sleep(500) WinSetState($hIE, "", @SW_MAXIMIZE) ;Wait for a browser page load to complete Sleep(3000) _IENavigate($oIE, "https://properURL.com") Sleep(8000) _IELoadWait($oIE) ;Attach to a browser control embedded in another window $oIE = _IEAttach("https://"properURL.com", url") ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $oIE = ' & $oIE & @CRLF & '>Error code: ' & @error & ' Extended code: 0x' & Hex(@extended) & @CRLF) ;### Debug Console Sleep(2000) ;Get the title of the webpage ;Local $wTitle = _IEPropertyGet($oIE, "title") ;MsgBox($MB_SYSTEMMODAL, "Webpage title:", $wTitle) ;Clicks the new button Sleep(3000) _IEAction($nWorkOrderB, "focus") _IEAction($nWorkOrderB, "click") Sleep(5000) ;Store the Element names where the important data will be sent ;Store the long description button Local $wLongDButton = _IEGetObjById($oIE, "m65d795a4-img") ;Store the long Description field id Local $wComments = _IEGetObjById($oIE, "ma6499a9c-rte_iframe") ;Store the ok button id that is in the long description Local $wCommOk = _IEGetObjById($oIE, "m74031266-pb") ;******************************************************************************* ; Send the stored data to the proper field ;******************************************************************************* ;Click the long description button Sleep(300) _IEAction($wLongDButton, "focus") _IEAction($wLongDButton, "click") Sleep(300) ;Sends the Comments Sleep(500) _IEAction($wComments, "focus") _IEAction($wComments, "click") Sleep(500) _IEFormElementSetValue($wComments, "hello darkness my old friend") ;Click the ok button Sleep(500) _IEAction($wCommOk, "focus") _IEAction($wCommOk, "click") Sleep(500)  
      Here is the popup:

    • yasha
      By yasha
      i want am trying to select a nimber to run a program and then select where to save the excel result at before hand
      the problem is that it does not save in the folder i want but the folder before any solutions
      #.................
      $sFolder = ""
          ; Create a constant variable in Local scope of the message to display in FileSelectFolder.
          Local Const $sMessage = "Select a folder"
          ; Display an open dialog to select a file.
          $sFileSelectFolder = FileSelectFolder($sMessage, $sFolder)
          If @error Then
              ; Display the error message.
              MsgBox($MB_SYSTEMMODAL, "", "No folder was selected.")
          Else
              ; Display the selected folder.
              MsgBox($MB_SYSTEMMODAL, "", "You chose the following folder:" & @CRLF & $sFileSelectFolder)
          EndIf
      .......
      ........
      $oExcel = ObjCreate("Excel.Application")                   ; Create an Excel Object
      $oExcel.Visible = 1                                        ; Let Excel show itself
      $oExcel.Workbooks.Open("J:\OPS\OPS_Share\Planners\2 - Weekly Reports\Auto download\"& $YY & $MM & $DD & " ORDER.xls",0)
      $oExcel.ActiveWorkbook.Saveas ( $sFileSelectFolder,""& $YY & $MM & $DD & " ORDER.xlsx", 1)
      $oExcel.ActiveWorkBook.Close
      $oExcel.Quit
      i only want to save it as ddmmyy order inside documents but it saves in libraries as documents ddmmyy order.
    • vynce1982
      By vynce1982
      I am trying to make a simple installer script for my understanding.  I would just like to understand how to deal with multiple possible windows. In the case of installing VLC, I might get a window saying VLC is already installed. I have also tried a switch with no luck.  I would just like to understand some methods for dealing with the possible existence of unexpected windows. 
       
      ;INSTALL VLC VIEWER
      Run(@ScriptDir & '\bin\VLCViewer_2.2.4_3.EXE')
      AutoItSetOption('MouseCoordMode', 0)
      sleep(4000)
      WinWait("VLC Viewer 2.2.4")

           ; this window will pop up if vlc is already installed
          If WinExists( "VLC Viewer 2.2.4", "VLC 2.2.4 Already Installed") Then
                ConsoleWrite ("already installed")
                WinActivate ('VLC Viewer 2.2.4','Already Installed')
                MouseClick ('primary', 93, 83, 1, 0)
                
          EndIf
       
            ; this window will pop up if installer finishes sucessfully
           If WinExists( "VLC Viewer 2.2.4", "VLC Viewer 2.2.4 Installed") Then 
                ConsoleWrite ("already installed")
                WinActivate ('VLC Viewer 2.2.4','VlC Installed')
                MouseClick ('primary', 93, 83, 1, 0)
         EndIf

       
       
       
×