Problem with FileGet on Device

BerndB

Member
Licensed User
Hi all,

I get different effects on FileGet on Desktop or Device.

I read a Textfile with FileGet, because I want to access lines at particular points later on.
The startByte of every Line is saved in a FilePointer-List FP (array).

One set of Data is read and looked for CrLf.
This tells where the new Line begins.

On the Desktop everything works fine.
see first Attachment:
The Number tells the startByte to read from, the text is from the File at that point up to CrLf.

On the Device sometimes there comes up failures.
see second Attachement:
In line 8 (the startByte 122 is correct) there is one. Line 9 is an aftereffect.
The last two lines are a failure again. The startByte 255 is correct.

Does anybody has an idea.
Code and Textfile is attached.

Thanks a lot

Bernd


This is created with version 5.
But compiled with version 6 is the same.
As well if I compile on the device with Version 6.01.

.Net Version on the Device is: 2.0.7045


The code is condensed from a larger app.
B4X:
Sub Globals
  'Declare the global variables here.
   nHeader =3
   eof_ = false
   Dim c1
   z=0
End Sub

Sub App_Start
  Sip(False)
  num1.Visible = false  

  AddArrayList("FP") ' FilePointer 
  Form1.Text="AltiRoute"
  Form1.Show ' muß vor drawer stehen
  tb1.Text=""
End Sub


Sub mnLoad_Click
  open1.Filter = "rt2 Files|*.rt2|AllFiles|*.*"
  If open1.Show = cCancel Then Return
  If FileExist (open1.File) = true Then
    Form1.Text = open1.File 
    eof_ = false
    FP.clear       ' FilePointer
    FileClose(c1)
   'FileOpen (c1,open1.File,cRead ,, cASCII)' doesn't work with FileGet
    FileOpen (c1,open1.File,cRandom)
    FP.add(0)      ' FilePointer first Value
    For i = 1 To nHeader 
     header =getLine(FP.Item(FP.count-1))   
     'header = FileRead (c1) 
     FP.add(getFP(header))
    Next
    'line1 = FileRead (c1)
    line1 =getLine(FP.Item(FP.count-1))
    FP.add(getFP(line1))
    Do    
      'line1 = FileRead (c1)
     line1 =getLine(FP.Item(FP.count-1))
     FP.add(getFP(line1))
     z=z+1
    Loop Until (line1 = EOF)or(EOF_)or(z>10)
 
  End If 'If FileExist
 
End Sub


Sub getLine(FP1)
  tb1.Text=tb1.Text &crlf &FP1 &"   "   'for debugging
  l1 =FileGet(c1,FP1,50) 
  'l1 =FileGet(c1,143,50)     'for debugging
  'tb1.Text=tb1.Text  &l1 &"*" &crlf   'for debugging
  Pos = StrIndexOf(l1,crlf,0)
  'truncate inputline at crlf
  If Pos <> -1 Then 
    l1 =SubString(l1,0,Pos)
  End If
  If StrIndexOf(l1,",",0) = -1 Then 
   eof_ = true
  Else
   eof_ = false
  End If      
  tb1.Text=tb1.Text  &l1      'for debugging
  Return l1
End Sub

Sub getFP(l1) 'next value for FilePointer-List
  Return FP.Item(FP.count-1) +StrLength(l1)+2   ' +2: Cr Lf
End Sub


Sub Form1_Close
  FileClose (c1)
End Sub
 

Attachments

Erel

Administrator
Staff member
Licensed User
Why don't you use a (hidden) Table and load the data with LoadCSV ?
 

BerndB

Member
Licensed User
Ok, I can do a workaround.

But why there is that difference.

Is there a failure in my code, or is it bug?

Thanks
Bernd
 

klaus

Expert
Licensed User
Hi BerndB,

I have tried your code on my desktop and on my Qtek 9090 WM2003,
and get the same problem.

I have added a textbox on your Form and MsgBoxes to go step by step and there are lines not read correctly (new code joined).
After these investigatios there is a problem with the FileGet function on the device.

I added a line
tx=FileGet(c1,122,40) '???????????????????
and with this additional line it works.
Why I don't know, perhaps Erel should have a look at this.

Best regards
 

BerndB

Member
Licensed User
Hi Erel,
Hi Klaus,

thanks for your investigations!

it even works with a dummy-read like this:

tx=FileGet(c1,1,0)

Concerning the workaround:
One reason why I work with FileGet is, that I access as well Files with a altitude- model witch have a size of about 4 MB with 6000 lines * 6000 columns.
There I want to pick every single altitude for the Koords e.g. in that Route file attached to create a altitude profile.
I didn't think of loading the whole 4MB into the app. Specially because it could be that i have to pick the altitudes from different altitude-files.

Erel, would you advise to load Files of that size into a table?

Thank you in respect of your time spending for b4PPC.

regards
Bernd
 

Erel

Administrator
Staff member
Licensed User
4MB is too large for a table.
However it will also be too slow using FileGet or FileRead.
The best solution is to convert the data to a SQLite database.
 

BerndB

Member
Licensed User
Thank you for your hint Erel.

I never worked with SQL.

So it seems it's time to get into it.

regards
Bernd
 

BerndB

Member
Licensed User
sqlite table access by row & column

Hi friends of sqlite,

I have a file with altitude levels converted to a sql-table.
Now I want to access the table by row and column.

What I found in the forum is this:

B4X:
  Reader.New1
  cmd.CommandText = "Select Alti.* from Alti Limit 1 offset 2"
  Reader.Value = Cmd.ExecuteReader 
  Msgbox(Reader.GetValue(3))
Alti is my Table
and with this code I get the content of the field from row 3 (offset 2) and column 4 (GetValue(3).

What I couldn't find is how to replace the integer for offset (2 in this case) with a variable.

Can somebody help me to get a quick random access on a sql-table (with use of variables).:sign0085:

Thanks a lot
Bernd
 

Erel

Administrator
Staff member
Licensed User
cmd.CommandText is a simple string:
B4X:
cmd.CommandText = "Select Alti.* from Alti Limit 1 offset " & Variable
 
Top