Android Question load to application start application .csv file

fgh3966

Active Member
Licensed User
Hello Everybody

I want to load a file for example csv file, that are into the directory Téléchargement and use it as if it had been supported by this sub.

B4X:
Private Sub HandleLoadResult(Result As LoadResult)
    If Result.Success Then
        Try
            Dim Reader As TextReader
            Reader.Initialize(File.OpenInput(Result.Dir, Result.FileName))
'             Dim line As String
            line = Reader.ReadLine
'            stringList.Add(line)
            Do While line <> Null
                line = Reader.ReadLine
                stringList.Add(line)
                increm = increm +1        ' nombre lignes dans le CSV
            Loop
            Reader.Close
    '        chainetexte = File.ReadString(Result.Dir, Result.FileName)
            toast.Show($"File '${Result.RealName}' loaded"$)
        Catch
            chainetexte = "Error loading file"
            'Log(LastException)
        End Try
    End If
'    LoadGTR2
    Log ("nbre lignes  "&increm)
'    txtField.Text = chainetexte   
End Sub

It is possible ?

Thanks.
 

Attachments

  • csvBase.zip
    13.8 KB · Views: 20

fgh3966

Active Member
Licensed User
Hello all

Excuse my bad English

The process around Reader is difficult to understand.
When starting application, Reader should load with a csv file and the file name and path would be indicated by variables.
I think that i need two variables : One for the path and another for the file name.

I wrote the code below: it is executed but Reader did not load the csv file

B4X:
Private Sub HandleGO '(Result) ' As LoadResult)
Dim ffile, ppath As String
ppath = "Download"
ffile = "file2023.csv"

        Try
            Dim Reader As TextReader
            Reader.Initialize(File.OpenInput(ppath, ffile))
            
            etc ...

End Sub

Any help please ?
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Upvote 0

fgh3966

Active Member
Licensed User
in red color debugger say >>> Caused by: java.io.FileNotFoundException: Download/file2023.csv (No such file or directory)
It's android 8.01
How to know path into android with b4a ? I think the ls -l command is not working?
 
Upvote 0

teddybear

Well-Known Member
Licensed User
in red color debugger say >>> Caused by: java.io.FileNotFoundException: Download/file2023.csv (No such file or directory)
It's android 8.01
How to know path into android with b4a ? I think the ls -l command is not working?
Why do you use the Download directory? do you know its absolute path? where is the file2023.csv from?
 
Upvote 0

fgh3966

Active Member
Licensed User
I use the Download folder because it seems simple for users, maybe the documents folder?
If you recommend other places I'm willing to try.
I would like to code an app that is easy to use and if possible not too complicated to program .

file2023.csv are into download directory
 
Upvote 0

teddybear

Well-Known Member
Licensed User
I use the Download folder because it seems simple for users, maybe the documents folder?
If you recommend other places I'm willing to try.
I would like to code an app that is easy to use and if possible not too complicated to program .

file2023.csv are into download directory
Where is the file2023.csv from, third App? see your post#1, you are using contentchooser to get file, the directory is contentDir
 
Last edited:
Upvote 0

fgh3966

Active Member
Licensed User
I use using contentchooser to get file because this function are coded into an example (I don't really understand how it works)
New i want to load a csv file into Reader object or variable by specifying the path and name of the csv file

file2023.csv file are into Download directory
 
Upvote 0

teddybear

Well-Known Member
Licensed User
both are available in the ContentChooser Result event.

B4X:
    Wait For CC_Result (Success As Boolean, Dir As String, FileName As String)

You can use Dir and Filename in this Event
The example in post #1 it can read text file using CC, I don't know why to read file2023.csv by specified Download path in Post #3? so I asked where the file2023.csv is from.
 
Upvote 0

fgh3966

Active Member
Licensed User
Into filehandler i copy and rename Load As ResumableSub and disable cc.Show("text/*", "Choose text file")

B4X:
Public Sub StartLoad As ResumableSub
    Dim cc As ContentChooser
    cc.Initialize("cc")
'    cc.Show("text/*", "Choose text file")
    Wait For CC_Result (Success As Boolean, Dir As String, FileName As String)
    Dim res As LoadResult = CreateLoadResult(Success, Dir, FileName)
    If res.Success Then ExtractInformationFromURI(res.FileName, res)
    Return res
End Sub

Public Sub Load As ResumableSub
    Dim cc As ContentChooser
    cc.Initialize("cc")
    cc.Show("text/*", "Choose text file")
    Wait For CC_Result (Success As Boolean, Dir As String, FileName As String)
    Dim res As LoadResult = CreateLoadResult(Success, Dir, FileName)
    If res.Success Then ExtractInformationFromURI(res.FileName, res)
    Return res
End Sub

and into B4Xmainpage i copy btnload_clik sub

B4X:
Private Sub BtnLoad_Click 
    #if B4A
    Wait For (FileHandler1.Load) Complete (Result As LoadResult)
    #else if B4i
    Wait For (FileHandler1.Load(Me, B4XPages.GetNativeParent(Me).TopRightButtons.Get(1))) Complete (Result As LoadResult)
    #end if
    'txtField.textfield.enabled = True
    HandleLoadResult(Result)
End Sub

private Sub StartBtnLoad 
    #if B4A
    Wait For (FileHandler1.StartLoad) Complete (Result As LoadResult)
    #else if B4i
    Wait For (FileHandler1.Load(Me, B4XPages.GetNativeParent(Me).TopRightButtons.Get(1))) Complete (Result As LoadResult)
    #end if
    'txtField.textfield.enabled = True
    HandleLoadResult(Result)
End Sub

Now I have to pass variables between sub and classes.
 
Last edited:
Upvote 0
Top