Jump to content

Creating a new Array from existing Array using _ArrayAdd and _ArrayInsert


Go to solution Solved by Gianni,

Recommended Posts

Posted
Hey folks,
 
I am trying to create a new array from an existing array by adding/inserting values from the existing 20 column 2D array into a new 2 column 2D array if the row/column cell contains a value.
 
My thought was that I could use _ArrayAdd to add the first column into the new array, and then _ArrayInsert to insert data into the second column in the same row. The script that I have written is not inserting the data into the second column of the new array.
 
local $y
_FileReadToArray("students.csv",$aArray,0,",")
Local $aArray2[0][2]
for $x = 1 to ubound($aArray)-1
   if StringLen($aArray[$x][22]) Then
      $y += 1
      _ArrayAdd($aArray2, $aArray[$x][11], 0)
          _ArrayInsert($aArray2, $y, $aArray[$x][22],1)
   EndIf
Next

 

Your help is appreciated. Thank you.
Posted

try to use

$aArray2[$y][1] = $aArray[$x][22]

instead of

_ArrayInsert($aArray2, $y, $aArray[$x][22],1)

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Posted

Hi Chimp, thank you for your reply. I replaced the line and received the following error:

Array variable has incorrect number of subscripts or subscript dimension range exceeded.:
$aArray2[$y][1] = $aArray[$x][22]
^ ERROR
  • Solution
Posted

move   $y += 1 after  $aArray2[$y][1] = $aArray[$x][22]

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...