Hoping for some clarification on text and csv files

boastrike

Member
Licensed User
Longtime User
First, I have to say I am like a "kid in a candy store" working with B4A! I'm learning by leaps and bounds and developing faster than I would have thought possible on Android prior to discovering B4A. Thank you.

I am writing an app that will take data entered by a user and then sent as an attachment in an email as a PC readable CSV file. The file format would be a "header" record that has a location number on it followed by inventory records:

68433
12345,5
23456,7
4567,3
12345453,1
.
.
.

Can I use the SaveCSV function to create this file or are there any issues with creating this simple text file with the other file write options that would cause a problem with being able to read it or copy it into a spreadsheet? Is B4A intrepretation of CSV file the same as the above (without the header location record as I can merge that in later)? I am saving the inventory data in lists currently as well as displaying it in a listview to the user. Thanks for any input. Searching the forum I'm not quite getting my brain around it. I used the SaveCSV utility but when I copy it to the PC it doesn't show as above.

Thanks
 

NJDude

Expert
Licensed User
Longtime User
Let me asking you something, that file will have only 1 column and those values include a COMMA? if the answer is yes, then you can just save each record enclosed in quotes something like:

B4X:
Header = "Header"
Line1 = QUOTE & Value1 & QUOTE
Line2 = QUOTE & Value2 & QUOTE

etc etc

Then, create one line and save it to a CSV file.
 
Upvote 0

boastrike

Member
Licensed User
Longtime User
NJDude,

Thanks for the quick reply. If I am reading your question correctly then I would say each row in the file will comprise 2 columns (first is the item number and second is the quantity) and neither have comma's in their values and the process of using the SaveCSV would then separate them by a comma.

In my Process Globals I have orderline as:

Type orderline (item as string, qty as string)

In my code to write the file I have:

Dim CSVlist As List
CSVlist.Initialize
For i = 0 To lstorders.Size - 1
Dim row(2) As String
Dim s As orderline
s = lstorders.Get(i)
row(0) = s.item
row(1) = s.qty
CSVlist.Add(Array As String(row))
Next
Dim su As StringUtils
su.SaveCSV(File.DirRootExternal, "MailList.csv", ",", CSVlist)


When I look at the MailList.csv output I see the following (I have not yet written or worried about the top header record as I believe I can just merge the two files and make a final file to send via email as the attachment:

[Ljava.lang.String;@4067bc90
[Ljava.lang.String;@405eae08
[Ljava.lang.String;@4068bab8
[Ljava.lang.String;@406a0040

Thanks, boastrike
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…