B4J Question b4j kvs2 multi-column csv

jimich

Member
Licensed User
Longtime User
Good day to all,

I have code below. Everything is ok except when using kvs.get(), which I could not get every item on the list.

Thank you for your kind reply.

B4X:
'Non-UI application (console / server application)
#Region Project Attributes
    #CommandLineArgs:
    #MergeLibraries: True

    #AdditionalJar: bcprov-jdk15on-154
    #AdditionalJar: sqlite-jdbc-3.7.2
#End Region

Sub Process_Globals
    Public kvs As KeyValueStore

    Dim su As StringUtils
   
End Sub

Sub AppStart (Args() As String)

    '--------------------------------------------------------------------
    Dim folder As String = File.DirApp
    kvs.Initialize(folder, "datastore")
    '--------------------------------------------------------------------

    '--------------------------------------------------------------------
    'delete all data
    kvs.DeleteAll
    '--------------------------------------------------------------------
   
    '--------------------------------------------------------------------
    'put a "simple" value
    kvs.Put("time", DateTime.Now)

    'get it
    Dim xtime As String = kvs.Get("time")
    Log(DateTime.Time(xtime))
    '--------------------------------------------------------------------

    '--------------------------------------------------------------------
    'this ok!
    Dim s As String
    Dim list1 As List = su.LoadCSV(File.DirAssets, "product.csv",",")
   
    For Each row() As String In list1
        s=""
        For Each n As String In row
            s=s & "   " & n
        Next
        s = s & CRLF
        'Log(s)
    Next
    '--------------------------------------------------------------------

    '--------------------------------------------------------------------
    'put it on kvs
    kvs.put("test", list1)
   
    Dim s As String
   
    'list it
    For Each row() As String In list1
        s=""
        For Each n As String In row
            s=s & "   " & n
        Next
        s = s & CRLF
        Log(s)
    Next
    '--------------------------------------------------------------------
   
    '--------------------------------------------------------------------
    'get
    'and here lies the problem
    Dim s2 As String=""
    Dim list2 As List = kvs.Get("test")
    For Each row() As String In list2
        s2=""
        For Each n As String In row
            s2=s2 & "   " & n
        Next
        s2 = s2 & CRLF
        Log(s2)
    Next
    '--------------------------------------------------------------------

End Sub

'Return true to allow the default exceptions handler to handle the uncaught exception.
Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
    Return True
End Sub
 

Attachments

  • _kvs_testonly.zip
    56 KB · Views: 341

DonManfred

Expert
Licensed User
Longtime User
B4X:
    '--------------------------------------------------------------------
    'get
    Dim list2 As List = kvs.Get("test")
    'Log(list2)
    For Each row2() As Object In list2
        Dim s2 As String=""
        For Each n As String In row2
            s2=s2 & "   " & n
        Next
        s2 = s2 & CRLF
        Log(s2)
    Next
    '--------------------------------------------------------------------

13:24:59
ref product
1 samsung note 1
2 samsung note 2
3 samsung note 3
4 samsung note 4
5 samsung note 5
6 samsung note 6
7 samsung note 7
8 samsung note 8
9 samsung note 9
10 samsung note 10
ref product
1 samsung note 1
2 samsung note 2
3 samsung note 3
4 samsung note 4
5 samsung note 5
6 samsung note 6
7 samsung note 7
8 samsung note 8
9 samsung note 9
10 samsung note 10
 
Upvote 0

jimich

Member
Licensed User
Longtime User
B4X:
    '--------------------------------------------------------------------
    'get
    Dim list2 As List = kvs.Get("test")
    'Log(list2)
    For Each row2() As Object In list2
        Dim s2 As String=""
        For Each n As String In row2
            s2=s2 & "   " & n
        Next
        s2 = s2 & CRLF
        Log(s2)
    Next
    '--------------------------------------------------------------------


Thank you very much DonManfred!

God bless!
 
Upvote 0
Top