Problem with text file

anallie0

Active Member
Licensed User
Longtime User
Hi
I memorize some data into a text file.
are stored in this order:

TextWriter1.WriteLine(Colore)
TextWriter1.WriteLine(" N° ")
TextWriter1.WriteLine(Numpaz)
TextWriter1.WriteLine(" T ")
TextWriter1.WriteLine(Valcrono)
TextWriter1.WriteLine(" La ")
TextWriter1.WriteLine(Lati)
TextWriter1.WriteLine(" Lo ")
TextWriter1.WriteLine(Longi)
TextWriter1.WriteLine(" --- ")

Then I read them to put them in a listview with this code.

B4X:
Sub pulslista_Click

panelreport.Visible=False
panellist.Visible=True

Dim colo, nume, tem, lat, lon, app As String


Dim icgiallo, icblu, icverde, icrosso As Bitmap

   icgiallo.Initialize(File.DirAssets, "icogiallo.png")
   icblu.Initialize(File.DirAssets, "Icoblu.png")
   icverde.Initialize(File.DirAssets, "Icoverde.png")
   icrosso.Initialize(File.DirAssets, "Icorosso.png")

   

   
      Dim TextReader1 As TextReader
      
      TextReader1.Initialize(File.OpenInput(File.DirDefaultExternal & "/TriageDir", "Report.txt"))    
   
         'Do While TextReader1.ReadLine <> Null
         
         colo = TextReader1.ReadLine'(Colore)
         app = TextReader1.ReadLine'(" N° ")
         nume = TextReader1.ReadLine'(Numpaz)
         app = TextReader1.ReadLine'(" T ")
         tem = TextReader1.ReadLine'(Valcrono)
         app = TextReader1.ReadLine'(" La ")
         lat = TextReader1.ReadLine'(Lati)
         app = TextReader1.ReadLine'(" Lo ")
         lon = TextReader1.ReadLine'(Longi)
         app = TextReader1.ReadLine'(" --- ")
         
   'If colo = "Verde" Then      
   lista.AddTwoLinesAndBitmap("N° " & nume & "  Tempo " & tem  , "Lat. " & lat & "  Lon. " & lon, icverde)
   'End If

'Loop
         
         
   TextReader1.close
         
   
End Sub

If I read the data once they are put in item correctly.

attachment.php



But if I run the code with the loop the data is all mixed.

attachment.php


What does not work?
thanks
 

Attachments

  • device-2012-09-25-234516.png
    device-2012-09-25-234516.png
    20.1 KB · Views: 365
  • device-2012-09-25-234409.png
    device-2012-09-25-234409.png
    78.9 KB · Views: 356

Geezer

Active Member
Licensed User
Longtime User
Do While TextReader1.ReadLine <> Null

When you have read the first line to check if it's null, everything else is out of sequence.

The value for colo would be lost and everything else would read as ...

app = TextReader1.ReadLine'(Colore)
nume = TextReader1.ReadLine'(" N° ")
app = TextReader1.ReadLine'(Numpaz)
tem = TextReader1.ReadLine'(" T ")

... and so on
 
Upvote 0

anallie0

Active Member
Licensed User
Longtime User
Do While TextReader1.ReadLine <> Null

When you have read the first line to check if it's null, everything else is out of sequence.

The value for colo would be lost and everything else would read as ...

app = TextReader1.ReadLine'(Colore)
nume = TextReader1.ReadLine'(" N° ")
app = TextReader1.ReadLine'(Numpaz)
tem = TextReader1.ReadLine'(" T ")

... and so on

Just, had not thought of.
But then how do I know when it ends the file (old eof). ?
 
Upvote 0

anallie0

Active Member
Licensed User
Longtime User
How do you save the data.
If you read the data exactly as you save it you don't need to check eof.
Just check if the file exists.

Best regards.

but my file is dynamic, I can have from one to infinite sets of data and do not know how many.
:)
 
Upvote 0

kickaha

Well-Known Member
Licensed User
Longtime User
B4X:
Sub pulslista_Clickpanel
report.Visible=False
panellist.Visible=True
Dim colo, nume, tem, lat, lon, app As String
Dim icgiallo, icblu, icverde, icrosso As Bitmap

Dim test as String

    icgiallo.Initialize(File.DirAssets, "icogiallo.png")
    icblu.Initialize(File.DirAssets, "Icoblu.png")
    icverde.Initialize(File.DirAssets, "Icoverde.png")
    icrosso.Initialize(File.DirAssets, "Icorosso.png")
    Dim TextReader1 As TextReader
    TextReader1.Initialize(File.OpenInput(File.DirDefaultExternal & "/TriageDir", "Report.txt"))

    test = TextReader1.ReadLine

    Do While test <> Null
        colo = test'(Colore)
        app = TextReader1.ReadLine'(" N� ")
        nume = TextReader1.ReadLine'(Numpaz)
        app = TextReader1.ReadLine'(" T ")
        tem = TextReader1.ReadLine'(Valcrono)
        app = TextReader1.ReadLine'(" La ")
        lat = TextReader1.ReadLine'(Lati)
        app = TextReader1.ReadLine'(" Lo ")
        lon = TextReader1.ReadLine'(Longi)
        app = TextReader1.ReadLine'(" --- ")
        If colo = "Verde" Then
            lista.AddTwoLinesAndBitmap("N� " & nume & "  Tempo " & tem  , "Lat. " & lat & "  Lon. " & lon, icverde)
        End If

    test = TextReader1.ReadLine

    Loop
    TextReader1.close
    End Sub
 
Upvote 0
Top