simple scrollview question

Hodi

Member
Licensed User
Longtime User
Hi together,
I´ve started with B4A some days ago and need help with a really small project. I want to search with a edit text in a CSV file the first Column and want to show the third data of the same row in scrollview.

The csv looks like:
Number,high,weight
3,13,234
3,12,334
5,10,122
5,12,244
5,13,330

so, when I typ 5 in the edit text I will show the scollview with
Number weight
5 122
5 244
5 330

Please can everybody explain a simple way to get the result?

Thanks in advance
hodi
 

Hodi

Member
Licensed User
Longtime User
Hi NJDude,
First, many thank you for your quick reply. The hole file have round about 400 rows but I´ve started with B4A right now and SQLite shows very complicated. At first I have to convert the csv to SQL, right?

regards,
Hodi
 
Upvote 0

NJDude

Expert
Licensed User
Longtime User
Yes, you will have to convert the CSV to SQL, you could use THIS program to import the CSV into a SQLite database. If you don't feel comfortable using B4A and SQLite just yet, then use a small version of you CSV and work with arrays.
 
Upvote 0

Caravelle

Active Member
Licensed User
Longtime User
I'd stick with your csv file in permanent storage for now, until you have more experience. Read the help about the data structure called a Map. When your program starts import the "number" and the "weight" elements of your complete csv file into a map, From then on you just look up "number" in the map and you get the "weight" out. Maps are very useful so it's good to get familiar with their use early on.

Hope that helps.

Caravelle.
 
Upvote 0

Hodi

Member
Licensed User
Longtime User
Yes, you will have to convert the CSV to SQL, you could use THIS program to import the CSV into a SQLite database. If you don't feel comfortable using B4A and SQLite just yet, then use a small version of you CSV and work with arrays.

Hi NJDude,

In the following code I tried to convert my CSV file to SQL and in the next step to put the columns in a map and show any column in a webview.
But the webview still be empty....
B4X:
Sub Process_Globals
 Dim SQL As SQL
End Sub
Sub Globals
   Dim btnImport As Button
   Dim WebView1 As WebView
End Sub
Sub Activity_Create(FirstTime As Boolean)
activity.LoadLayout ("main.bal")
If FirstTime Then
      SQL.Initialize(File.DirRootExternal, "Test1.db", True)
   End If
   DBUtils.DropTable(SQL, "Test1")
   WebView1.Visible = False
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub btnImport_Click
   Dim i, j As Int
Dim FileDialog1 As FileDialog
ProgressDialogShow("This process can take several minutes. Please wait!")
FileDialog1.FilePath = File.DirRootExternal
If FileDialog1.Show("Choose csv file", "Ok", "Cancel", "", Null) = DialogResponse.POSITIVE Then
SQL.Initialize(File.DirRootExternal, "test1.db", True)
SQL.ExecNonQuery("DROP TABLE IF EXISTS Table1")
SQL.ExecNonQuery("CREATE TABLE Table1 (col1 Text, col2 Text, col3 Text, col4 Text, col5 Text, col6 Text, col7 Text, col8 Text, col9 Text, col10 Text, col11 Text, col12 Text, col13 Text, col14 Text)")
SQL.BeginTransaction
Dim Reader As TextReader
Reader.Initialize(File.OpenInput(FileDialog1.FilePath, FileDialog1.ChosenName))
Try
Dim line As String
Reader.ReadLine
line = Reader.ReadLine
Do While line <> Null 
j = j + 1
line = Reader.ReadLine
If line.Contains("Result") OR line.Contains("#") Then
Else
Dim ColumnContent() As String
ColumnContent = Regex.Split(";", line)
For i = 0 To 13
ColumnContent(i) = ColumnContent(i).Replace(QUOTE, "")
Next
SQL.ExecNonQuery2("INSERT INTO Table1 VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?)", Array As Object (ColumnContent(0), ColumnContent(1), ColumnContent(2), ColumnContent(3), ColumnContent(4), ColumnContent(5), ColumnContent(6), ColumnContent(7), ColumnContent(8), ColumnContent(9), ColumnContent(10), ColumnContent(11), ColumnContent(12), ColumnContent(13)))
DoEvents
End If
Loop
Catch
Log(LastException.Message)
End Try
Reader.Close
SQL.TransactionSuccessful
SQL.EndTransaction
ProgressDialogHide
Msgbox("csv file imported!", "Message")
Else
Return True
End If
   WebView1.Visible = True
   Dim m As Map
   m.Initialize
   m.Put("TA-Nummer", DBUtils.DB_TEXT)
   m.Put("Material", DBUtils.DB_TEXT)
   m.Put("Vonplatz", DBUtils.DB_TEXT)
   DBUtils.CreateTable(SQL, "Test1", m, "")
   FillTest1Table
End Sub
Sub FillTest1Table
   Dim ListOfMaps As List
   ListOfMaps.Initialize
   Dim id As Int
   For i = 1 To 40
      Dim m As Map
      m.Initialize
      m.Put("TA-Nummer", "12345")
      m.Put("Material", "654321")
      m.Put("Vonplatz", "A001-01-01" & i)
      ListOfMaps.Add(m)
   Next
   DBUtils.InsertMaps(SQL, "Test1", ListOfMaps)
End Sub
Sub ShowTable1InWebView
   WebView1.Visible = True
   WebView1.LoadHtml(DBUtils.ExecuteHtml(SQL, _
      "SELECT Material, [Material] As Name FROM Test1" _
         , Null, 0, True))
End Sub
Please can check my code?
 
Upvote 0
Top