Sign in to follow this  
Followers 0
Burgs

FileReadToArray confusion

8 posts in this topic

Hello,

I am reading the following file into an array using the '_FileReadToArray' command:

-1, -1, 0
-1, -1, 1
-1, -1, 2
-1, -1, 3
-1, -1, 4
-1, -1, 5
-1, -1, 6
-1, -1, 7
-1, -1, 8
-1, -1, 9

When completed the 'Array[0]' reports that 10 records have been read into the array...which means 1 record per line, does this mean a 2D array has been created? I would have thought '30' records should have been reported as read (10 lines each of 3 values)...how do I access the values within the array,..? Is, for example, the '15th' array value (the first '-1' on the 6th line/record) accessed using something like 'myvalue = $aArray[6][0]"...? Thanks in advance...

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

The function only creates a 1D array as you can see from "Array[0] reports ..." which has only 1 index and therefore is a one dimensional array. You have to split the values of each line yourself.

Or you search the forum for a CSV read function like one.

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Did you check the output?

#include <File.au3>
#include <Array.au3>
_FileReadToArray($file, $array)
_ArrayDisplay($array)

Spoiler

“Hello, ladies, look at your man, now back to me, now back at your man, now back to me. Sadly, he isn’t me, but if he stopped using ladies scented body wash and switched to Old Spice, he could smell like he’s me. Look down, back up, where are you? You’re on a boat with the man your man could smell like. What’s in your hand, back at me. I have it, it’s an oyster with two tickets to that thing you love. Look again, the tickets are now diamonds. Anything is possible when your man smells like Old Spice and not a lady. I’m on a horse.”

 

Share this post


Link to post
Share on other sites

Thanks for the replies, yes I checked the output and I saw each of the 10 lines contains the 3 values...wow that is surprising I have to strip out the values into a 2D array...I thought the command would have done that already...thanks again.

Share this post


Link to post
Share on other sites

Why should the command do that? The help file says "Reads the specified file into an array" not "Reads the file and splits each line into separate values storing it in a 2D array".

How should the command know which structure the file has?

If it is a CSV format (Comma Separated Values) then the link I posted is what you need.

1 person likes this

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

I don't see what's so surprising. The command does as what it's called... reads the file into an array. A string of data is just that. Just because it has commas doesn't mean that it knows it's supposed to treat it like a CSV. Jus' Sayin'


Spoiler

“Hello, ladies, look at your man, now back to me, now back at your man, now back to me. Sadly, he isn’t me, but if he stopped using ladies scented body wash and switched to Old Spice, he could smell like he’s me. Look down, back up, where are you? You’re on a boat with the man your man could smell like. What’s in your hand, back at me. I have it, it’s an oyster with two tickets to that thing you love. Look again, the tickets are now diamonds. Anything is possible when your man smells like Old Spice and not a lady. I’m on a horse.”

 

Share this post


Link to post
Share on other sites

Is there by any chance a command to read values into a 2D array?

Share this post


Link to post
Share on other sites

As I posted above use the code written by ProgAndy.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

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  
Followers 0