Writing List to CSV File

Libor

Member
Licensed User
Longtime User
Hi I'm trying to write a list to CSV but my phone gives some kind of Java exception error when I try to do this.

It's not a permissions thing because I write to the same location with File.WriteList and it works fine.

Here is the code snippet. Thanks for any advice, I commented out the SaveCSV in order to try the File.Write.List.

They use the same data and destination for the write. I'm running this on the Samsung with the 2.2 Android on it.

Also as a second note I can't find a way to append a file so I thought that the SaveCSV might do that for me.


Dim su As StringUtils
Dim FileName As String
FileName = (NameTxt.Text & ".txt")
Msgbox("FileName Value is " & Filename & "and Dir is " & AppProfileDir, "")
Msgbox("This is the ProfileList " & ProfileList, "")
'su.SaveCSV(AppProfileDir, FileName, ",", ProfileList)
File.WriteList(AppProfileDir, FileName, ProfileList)

thanks for any ideas.
 
Last edited:

Libor

Member
Licensed User
Longtime User
File.WriteList line fails?
What is the error? You can get it from LogCat tab.

Sorry I put that in a confusing way.

The File.WriteList works but I wanted to use the su.SaveCSV and that failed.

This fails.


Dim su As StringUtils
Dim FileName As String
FileName = (NameTxt.Text & ".txt")
Msgbox("FileName Value is " & Filename & "and Dir is " & AppProfileDir, "")
Msgbox("This is the ProfileList " & ProfileList, "")
su.SaveCSV(AppProfileDir, FileName, ",", ProfileList)

The error I get on the line: su.SaveCSV(AppProfileDir, FileName, ",", ProfileList)

is:

java.lang.ClassCastException:java.lang.String

That's all the information in there.

Any idea?

thanks
 
Upvote 0

agraham

Expert
Licensed User
Longtime User
I suspect that your data in ProfileList is not in the correct format. The fact that WriteList works would tend to confirm this.

From the help for SaveCSV
"Table - A List with arrays of strings as items. Each array represents a row. All arrays should be of the same length."

You can append to a file
From the help for File.OpenOutput
"OpenOutput(Dir As String, FileName As String, Append As Boolean)"
 
Upvote 0

Libor

Member
Licensed User
Longtime User
Yes, it seems you're right.

I'm confused by the relationship of array to List. I'm reading the documentation but I can't seem to get my brain around this piece.

Do I have to use an array to populate the list and have the write done in a CSV format?

I have only 5-10 items there and I basically add them to a list based on a form that's filled out. Each of these forms represents a profile. I put each into it's own text file. Probably not very efficient but I'm still just learning.

So I have each item in it's own line and I name each file to represent the profile.

This was pretty easy to do. But then I thought what if I wanted to put the data into a single file, put the name in as part of the data and make each record a comma delimited row.

This is the part that's evading me using this method.

Thanks for the pointer on append. I'm trying to figure out how to use that.

I think I could do it a different way by manipulating the entries, appending them to the variable used to store them before the write one at a time and putting commas in between but that seems like a lot of extra work.
 
Upvote 0

Libor

Member
Licensed User
Longtime User
Thanks everyone, I'm trying different things while I think about how this program could be designed. I have a feeling there will be lots more questions.
 
Upvote 0
Top