Jump to content

How to read an array element from an internal array?


ur
 Share

Recommended Posts

I am reading a CSV file which is tab seperated as below.

Local $aArray = FileReadToArray($file)

And now, I am splitting this main array record wise so that Array contains internally another arrow to represent each row.

For $i = 0 to (UBound($aArray) - 1)
       ;MsgBox(0,"",$aArray[$i])
       $aArray[$i] = StringSplit(StringStripCR($aArray[$i]), Chr(9),2);Chr(9) for tab
       ;_ArrayDisplay($aArray[$i])
Next

Afther that, _ArrayDIsplay is able to see the individual internal arrays.

_ArrayDisplay($aArray[1])

But If I try to access the individual element of it as below.It is not showing any result.

MsgBox(0,"",$aArray[1][1])

Any suggestion, below is the sample csv file.

New Text Document.csv

Edited by ur
Link to comment
Share on other sites

You are ending up with an array of arrays... easier solution, use _FileReadToArray

#include <Array.au3>
#include <File.au3>

Local $aArray 
_FileReadToArray("E:\AutoIT\Programs\Test\New Text Document.csv", $aArray, 1, " ")
_ArrayDisplay($aArray)
MsgBox(0,"",$aArray[1][2])

You can specify multiple delimiter characters in the final argument.

Problem solving step 1: Write a simple, self-contained, running, replicator of your problem.

Link to comment
Share on other sites

Local $subArray[4] = [1,2,3,4]
Local $parentArray[1] = [$subArray]
_ArrayDisplay($parentArray[0])
For $i = 0 To UBound($parentArray[0])-1
    ConsoleWrite(($parentArray[0])[$i] & @CRLF)
Next

Direct answer to your question ^

You can also create a temporary variable, and set that to the internal array, and then loop through that temp array.

Edited by jdelaney
IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
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

×
×
  • Create New...