Multiple Arrays In .csv File


mawright89

Recommended Posts

Am looking to save multiple big arrays in a single .csv file, is it possible to use:

try

private handle = file.open("N:\NewRig\Calibration Files_DO NOT DELETE\Rig1Cal.csv", 0,1, 0, 1)

file.WriteDelim(handle,CalValues, ",", chr(10))

file.close(handle)

catch()

? strLastError

endcatch

for each array and just change the red part for the relevant array name?

Then use:

try

private handle = file.open("N:\NewRig\Calibration Files_DO NOT DELETE\Rig1Cal.csv", 1, 0, 0, 1)

CalValues = file.readDelim(handle, -1, ",", chr(10), 0)

file.close(handle)

catch()

? strLastError

endcatch

and just change the red value for the array I want to extract....?

Link to comment
Share on other sites

It is, except that you'd also need to change the file name, otherwise you'd overwrite the previous file. Because CSV files are variable field width, creating code to write one column at a time would be quite inefficient. If you have a bunch of arrays and you want to write them to a single file, you need to create a single two dimensional array. For example, if your arrays were cal1, cal2, and cal3:

private out

out[][0] = cal1

out[][1] = cal2

out[][2] = cal3

file.writeDelim(handle, out, ",", chr(10))

Link to comment
Share on other sites

private out

private[][0] = cal1

private[][1] = cal2

private[][2] = cal3

file.writeDelim(handle, out, ",", chr(10))

thankyou for the response, should the code above be out[][0], i dont see why private[][0] would work?

Is this essentially trying to put an array inside another array?

Link to comment
Share on other sites

Im also having trouble fetching string back from an array:

try

private handle = file.open("M:\ME Projects\Valve Database\" + ValveIDtype + ValveIDrevision + "\Leakspools.csv", 1, 0, 0, 1)

leakspools = file.readDelim(handle, -1, ",", chr(10), 0)

file.close(handle)

catch()

? strLastError

endcatch

the array in the .csv file has text {A1, A2, A3,...} ect... but when I use the code above the array variable leakspools becomes {1,2,3,....}. where has the string gone. The variable is declared as a string in the startup sequence.

Link to comment
Share on other sites

Sorry. Don't know what I was thinking. Yes, all those private[] should be out[]. I'm going to correct my post.

As for the read delim issue, if you have strings in your file you have to specify 1 at the end of readdelim to tell it to process the data as strings.

Link to comment
Share on other sites

As for the read delim issue, if you have strings in your file you have to specify 1 at the end of readdelim to tell it to process the data as strings.

Have tried changing the 0 to a 1 but im still getting only the numerical value

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.