Jump to content

adding data to a column in a 2d array


RickB75
 Share

Recommended Posts

Guys,

Been a while since I've been on here. I've ran into a stumbling block with a 2d array. Briefly, here's what I have. I've created a  zero based 2d array with 4 columns total. I have a loop using items from the 3rd column to fetch items and populate the 4th column. As I'm looping through I would love to just write to that particular position / column in the array. I can build and display a 1d array with the data built and it looks perfect. I keep running into problems though trying to insert the data. I can use arrayadd and it only add's the data at the end of the array which I expected but for testing, It works. Just adds the data in the wrong position. 

I guess my question is, if you guys want to data from one array to a specific position in a diff array via a loop, how do you do this?? What function? Right now, I'm kinda lost. 

 

 

Link to comment
Share on other sites

If you want to add data to the 4th column, your array has to have a 4th column first. You can't pick and choose which rows will have a 4th column, they all have to have it. You can use _ArrayColInsert, if you don't want to write it yourself, to make it easier for you.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

By 4th column, do you mean $aArray[$iRow][4] or [3] (0-indexed)?  In other words, is your [0] column your first column or your zeroth column?

Personally I never did like thinking of arrays in columns and rows, rather just dimensions. Those dimensions could represent anything. The file cabinet, trash can, VW Bug trunk, pickle jar, or watever other enumerated thing that can hold things and things.

Edited by VeryGary
Link to comment
Share on other sites

sorry for the late reply guys. Had dinner and kids homework to tend to :) As I run the  script, I check for the Array structure with a 4th column built.  I guess I was hoping to insert data through out the array as I'm looping through my main loop and use the positioning in my main loop for the positioning in the Array. I can build the seperate array and then Insert the data i guess. I just feel more comfortable to add to the array as I'm looping through it. my array structure is this.  $aTemp [0][4]

Link to comment
Share on other sites

Well... I ended up building another array identical to my first array ($aTemp [0][4]) and named it $aTemp2 [0][4]. I'm populating it via the _ArrayAdd function at the end of my For To Loop using a ubound counter from the first array. It seems like an unnecessary  additional step since the first array is already pre built with an empty column just sitting there. You have to basically build a string with delimiters and then split the string on the delimiters to insert into the array.  Seems like there would be a function similar to _ArrayAdd that you could define the positions on where you want to add the data instead of at the end of the Array. I tried using _ArrayInsert but it is inserting an entire additional row. Maybe, I'm just using it wrong. Who Knows :) 

_ArrayAdd($aTemp2,$aTemp[$i][0] & "|" & $aTemp[$i][1] & "|" & $aTemp[$i][2] & "|" & $SecString[0],0,"|" )

 

Link to comment
Share on other sites

Post a runnable version of your script so we can see what you're doing and how you're doing it. You're explanations are vague and not helping get to the problem you're trying to get past. _ArrayAdd is more than likely the last thing you'd need to use, but it's hard to say because no one is really sure what you're doing.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Ok. First of all, thank you guys so much for your advice and help.  It is truly very much appreciated. I'm always very humbled by everyone's willingness to offer help!!! I'm gonna try and put this together so everyone can understand what I'm trying to accomplish and show me a smarter / better way to accomplish my goal.  

 

Here is a example of my code that I have working now.  What I would love to have is, instead of building the 2nd Temp array, I already have the additional column in the first array ($aArray_Base). I have the data that I want to insert into that first array ($aArray_Base) in the $aTemp1 array. How can I loop through the $aTemp1 array and Place "A" in the correct position ( [0][3] ), "B" in the next position ([1][3], and so on...

#include <Array.au3>

Local $aArray_Base[10][4]
For $i = 0 To 9
    For $j = 0 To 2
        $aArray_Base[$i][$j] = $i & " - " & $j
    Next
Next
_ArrayDisplay($aArray_Base, "2D - Original")


Local $aTemp1[11] = ['A','B','C','D','E','F','G','H','I','J','K']

_ArrayDisplay($aTemp1, "1D - Original")


Local $aTemp2 [0][4]
For $i = 0 To UBound($aArray_Base) -1


    _ArrayAdd($aTemp2,$aArray_Base [$i][0] & '|' & $aArray_Base [$i][1] & '|' & $aArray_Base [$i][2] & '|' & $aTemp1 [$i],0,'|')

Next

_ArrayDisplay($aTemp2,"Revised Array with Col Added")

Also, keep in mind for example purpose the $aTemp1 array is already built here. In my main script, I build $aTemp1 array via the loop. It's a simple 1D array with only 1 position in it. 

 

Edited by RickB75
Link to comment
Share on other sites

Like this?

#include <array.au3>
Local $aArray_Base[10][4]
For $i = 0 To 9
    For $j = 0 To 2
        $aArray_Base[$i][$j] = $i & " - " & $j
    Next
Next
_ArrayDisplay($aArray_Base, "2D - Original")


Local $aTemp1[11] = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K']

_ArrayDisplay($aTemp1, "1D - Original")


Local $aTemp2[0][4]
For $i = 0 To UBound($aArray_Base) - 1
    $aArray_Base[$i][3] = $aTemp1[$i]
Next

_ArrayDisplay($aArray_Base, "Revised Array with Col Added")

 

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

@BrewManNH That's all I had to do??? 

$aArray_Base[$i][3] = $aTemp1[$i]

Something so simple. I've been sitting here trying all diff kinds of functions and could not get it to work. 

I think I'm equally embarrassed and mad at myself right now for not knowing better! LOL 

 

Thank you!!! 

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...