B4J Question thread does not start

ivanomonti

Expert
Licensed User
Longtime User
thread does not start, I've followed your various suggestions but the thread does not start, and you get an error like, "Exception: wrong number of arguments"

Private Sub AsyncSetMap(obj as object) or Private Sub AsyncSetMap,,, nothing changes, always the same mistake

thansk

B4X:
#Region Project Attributes
    #MainFormWidth: 600
    #MainFormHeight: 600
    #CommandLineArgs:
    #AdditionalJar: sqlite-jdbc-3.7.2
#End Region

Sub Process_Globals
    Private fx As JFX
    Private MainForm As Form
    Private Button_close As Button
    Private Button_open As Button
    Private TableView_list As TableView
    Private sqlite As class_sqlite
    Private ProgressBar1 As ProgressBar
    Dim Thread1 As Thread
End Sub

Sub AppStart (Form1 As Form, Args() As String)
    MainForm = Form1
    MainForm.RootPane.LoadLayout("Layout1") 'Load the layout file.
    MainForm.Show
    sqlite.Initialize
    Thread1.Initialise("Thread1")
    resize_column_tableview
End Sub

Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
    Return True
End Sub

Sub Button_open_Click
    If Thread1.Start(Me, "AsyncSetMap", Null) = True Then
        ProgressBar1.Progress = -1
    End If
End Sub

Sub Thread1_Ended(endedOK As Boolean, error As String)
    Log(error)
    ProgressBar1.Progress = 0
End Sub

Private Sub AsyncSetMap

    Dim FC As FileChooser
    FC.Initialize
    FileChooserUtils.AddExtensionFilters4(FC,Array As String("CSV","Text FIles"),Array As String("*.csv","*.txt"),True,"Output Files",True)
    FC.Title = "Open file CSV"
    Dim FileName As String = FC.ShowOpen(MainForm)
    Dim DirParent As String = FC.InitialDirectory
    FileName = FileName.Replace(DirParent & "\","")' C:\Users\ivanomonti\Desktop\ExportSelfAgent.csv

    Dim myTextReader As TextReader
    myTextReader.Initialize(File.OpenInput(DirParent,FileName))
    Dim values As String = myTextReader.ReadAll
    myTextReader.Close
      
    Dim list As List
    list.Initialize
    list = Regex.Split(Chr(10),values)
      
    Dim count, error As Int
    count = 0
    error = 0
      
    TableView_list.Items.Clear
      
    Dim listexport As String
      
    For i=1 To list.Size-1
        Try
            count = count + 1
            values = list.Get(i)
            Dim m() As String = Regex.Split(";",values.Replace("""","").Replace("=","").Replace(Chr(10),""))
            Dim mp As Map
            mp.Initialize
            mp.Put("Name",m(4))
            mp.Put("Surname","")
            mp.Put("Phone",m(0))
            mp.Put("Status",m(14))
            If sqlite.client_add(mp) = True Then
                Dim Row() As Object = Array ( m(4).ToUpperCase, m(0).ToUpperCase, m(5).ToLowerCase & " " & m(6).ToLowerCase, m(14).ToLowerCase,m(15).ToLowerCase)
            End If
            TableView_list.Items.Add(Row)
        Catch
            count = count-1
            error = error+1
            listexport = listexport & Chr(10) & i & " " & values
        End Try
    Next
    File.WriteString(DirParent,"Report.txt",listexport)
    fx.Msgbox(MainForm,"The file " & FileName & " was successfully imported, we found errors (" & error & ") found in the saved report","Alert")
    fx.ShowExternalDocument(File.GetUri(DirParent,"Report.txt"))
End Sub

Sub Button_save_Click
  
End Sub

Sub resize_column_tableview
    TableView_list.SetColumnWidth(0, TableView_list.PrefWidth*25/100)
    TableView_list.SetColumnWidth(1, TableView_list.PrefWidth*5/100)
    TableView_list.SetColumnWidth(2, TableView_list.PrefWidth*15/100)
    TableView_list.SetColumnWidth(3, TableView_list.PrefWidth*15/100)
    TableView_list.SetColumnWidth(4, TableView_list.PrefWidth*40/100)
End Sub

Sub Button_close_Click
    ExitApplication
End Sub

Sub TableView_list_Resize (Width As Double, Height As Double)
    resize_column_tableview
End Sub
 

OliverA

Expert
Licensed User
Longtime User
Upvote 0

OliverA

Expert
Licensed User
Longtime User
Upvote 0

ivanomonti

Expert
Licensed User
Longtime User
in this way everything is executed, but the screen remains locked and progress of the progressbar blocked, without then seeing the tableview update until it finishes loading all the records, I would like the progress to be seen and the populace of the tableview also

1° step

B4X:
Sub Button_open_Click
    
        If RadioButton_telmar.Selected = True Then
            
            Dim FC As FileChooser
            FC.Initialize
            FileChooserUtils.AddExtensionFilters4(FC,Array As String("CSV","Text FIles"),Array As String("*.csv","*.txt"),True,"Output Files",True)
            FC.Title = "Open file CSV"
            FileName = FC.ShowOpen(MainForm)
            DirParent = FC.InitialDirectory
            
            FileName = FileName.Replace(DirParent & "\","")

            Dim myTextReader As TextReader
            myTextReader.Initialize(File.OpenInput(DirParent,FileName))
            values = myTextReader.ReadAll
            myTextReader.Close
            
            list.Initialize
            list = Regex.Split(Chr(10),values)
            
            count = 0
            errorcount = 0
            
            TableView_list.Items.Clear
            
            For i=1 To list.Size-1
                Thread1.Initialise("Thread1")
                Thread1.RunOnGuiThread("AsyncThread", Array As Object(i))
            Next
            
        Else
            fx.Msgbox(MainForm,"form to be completed","Alert")
            Return
        End If
        
    finisc_import
        
End Sub

2° Step

B4X:
Private Sub AsyncThread(row As Object)
    
    Try
        count = count + 1
        values = list.Get(row)
        Dim m() As String = Regex.Split(";",values.Replace("""","").Replace("=","").Replace(Chr(10),""))
        Dim mp As Map
        mp.Initialize
        mp.Put("Name",m(4))
        mp.Put("Surname","")
        mp.Put("Phone",m(0))
        mp.Put("Status",m(14))
        If sqlite.client_add(mp) = True Then
            Dim rows() As Object = Array ( m(4).ToUpperCase, m(0).ToUpperCase, m(5).ToLowerCase & " " & m(6).ToLowerCase, m(14).ToLowerCase,m(15).ToLowerCase)
            TableView_list.Items.Add(rows)
        End If
    Catch
        count = count-1
        errorcount = errorcount+1
        listexport = listexport & Chr(10) & row & " " & values
    End Try

    ProgressBar1.Progress = ProgressBar1.Progress+1
    
End Sub

3° Step

B4X:
Sub finisc_import
    File.WriteString(DirParent,"Report.txt",listexport)
    fx.Msgbox(MainForm,"The file " & FileName & " was successfully imported, we found errors (" & errorcount & ") found in the saved report","Alert")
    fx.ShowExternalDocument(File.GetUri(DirParent,"Report.txt"))
End Sub
 
Upvote 0

OliverA

Expert
Licensed User
Longtime User
Upvote 0
Top