Android Question Problem in SaveTableToCSV in table.bas V. 2.28???


Licensed User
Crash using flexible Table , Table.bas version2.28.......

1) Reading a table (Citylist_sc.csv) into view works fine with

"Table1.LoadTableFromCSV2(File.DirDefaultExternal, "//NGT/t/citylist_sc.csv", True, ";", True)"

2) Editing only one field works fine with

Table1.UpdateCell(col, row, strNameText )

3) Save to CSV File (citylist_sc_Written.csv) works fine using

Table1.SaveTableToCSV(strPfad, "citylist_sc_Written.csv")

4) !!!!!!!!
After that Saving the File (citylist_sc_Written.csv), You you are not able to use/read this file into a new Table, it is crashing with Error when executing:

Public Sub SetColumnsWidths(Widths() As Int)
Dim v As View
Dim w As Int
For col = 0 To Widths.Length - 1
v = Header.GetView(col)
w = Max(2dip, Widths(col) - cLineWidth)
v.Width = w '(Crashing here!!!!)
If col > 0 Then
v.Left = Header.GetView(col - 1).Left + Widths(col - 1)
End If

Error: java.lang.runtimeExeption: Objekt should first be initialized (View) .....

When you have a look at the two files with notepad++, you will see, that in the original file (citylist_sc.csv), there are "CRLF" at the end of row..

After saving the File (citylist_sc_Written.csv) , there are only "LF" At the end of row.. It seems that only "CRLF" rows could be read?

What is going wrong? Bug in "Table1.SaveTableToCSV" command?

Could anyone reproduce my problem? Need help..



    481 bytes · Views: 150


Licensed User
Longtime User
The problem are not "CRLF" and "LF".
The problem is the separator character!
In the citylist_sc.csv file it is a semi-colon and in the citylist_sc_Written file it is a comma!
SaveTableToCSV saves by default with a comma as separator character.
I will add SaveTableToCSV2 with the separator character as a parameter.
If you want, in the mean time, you can add the routine below in the Table class module.

'Saves the table to a CSV file with a given separator character.
Public Sub SaveTableToCSV2(Dir As String, Filename As String, SeparatorChar As String)
    Dim headers(mNumberOfColumns) As String
    For i = 0 To headers.Length - 1
        Dim L As Label
        L = Header.GetView(i)
        headers(i) = L.Text
    StringUtils1.SaveCSV2(Dir, Filename, SeparatorChar, Data, headers)
End Sub
Upvote 0