Sub Process_Globals
Private BANano As BANano 'ignore
' make a variable to hold the Papa javascript object
Private PapaParse As BANanoObject
End Sub
Sub AppStart (Form1 As Form, Args() As String)
' The name of your library. Strongly suggested to let it begin with BANano!
BANano.Initialize("BANano", "BANanoCSV", DateTime.Now)
' add the papaparse.min.js file. Must be in the /Files folder of your project (do not forget to sync in the Files tab!)
BANano.Header.AddJavascriptFile("papaparse.min.js")
' start the build
BANano.Build(File.DirApp)
End Sub
Sub BANano_Ready()
' assign the JavaScript Papa variable to our B4J PapaParse variable
PapaParse.Initialize("Papa")
' CSV as a string example
Dim SB As StringBuilder
SB.Initialize
SB.Append($"col1a",15"$ & CRLF)
SB.Append($"col1b",20"$ & CRLF)
SB.Append($"col1c",30"$)
Dim MyCSV As String = SB.ToString
' or for example from a file on your server
Dim MyCSV As String = BANano.Await(BANano.GetFileAsText("http://gorgeousapps.com/sample.csv", Null, "UTF-8"))
' set some options of the PapaParse library
Dim Options As BANanoObject
Options.Initialize5
Options.SetField("dynamicTyping", True)
Options.SetField("skipEmptyLines", True)
' run the parse method on the PapaParse library
Dim result As BANanoObject
result = PapaParse.RunMethod("parse", Array(MyCSV, Options)).Result
' returns a list of lists
Dim MyArray As List = result.GetField("data")
Log(Get(MyArray, 0,0)) ' result is MyArray(0,0)
End Sub
' helper method to get a value from the list of lists object
Sub Get(Arr As List, indx1 As Long, indx2 As Long) As Object
Return Arr.Get(indx1).As(List).Get(indx2)
End Sub