Problem with FileGet on Device

Discussion in 'Questions (Windows Mobile)' started by BerndB, Apr 25, 2008.

  1. BerndB

    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


    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.
    Sub Globals
    'Declare the global variables here.
       nHeader =3
       eof_ = 
    Dim c1
    End Sub

    Sub App_Start
      num1.Visible = 

    "FP"' FilePointer 
    ' muß vor drawer stehen
    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_ = 
    ' FilePointer
    'FileOpen (c1,open1.File,cRead ,, cASCII)' doesn't work with FileGet
        FileOpen (c1,open1.File,cRandom)
    0)      ' FilePointer first Value
        For i = 1 To nHeader 
         header =getLine(FP.Item(FP.count-
    'header = FileRead (c1) 
    'line1 = FileRead (c1)
        line1 =getLine(FP.Item(FP.count-1))
    'line1 = FileRead (c1)
         line1 =getLine(FP.Item(FP.count-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,
    End If
    If StrIndexOf(l1,",",0) = -1 Then 
       eof_ = 
       eof_ = 
    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

    Attached Files:

  2. Erel

    Erel Administrator Staff Member Licensed User

    Why don't you use a (hidden) Table and load the data with LoadCSV ?
  3. BerndB

    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?

  4. Erel

    Erel Administrator Staff Member Licensed User

    It will be much faster and simpler to use a table.

    I'm checking it right now.
  5. klaus

    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
  6. BerndB

    BerndB Member Licensed User

    Hi Erel,
    Hi Klaus,

    thanks for your investigations!

    it even works with a dummy-read like this:


    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.

  7. Erel

    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.
  8. BerndB

    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.

  9. BerndB

    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:

      cmd.CommandText = 
    "Select Alti.* from Alti Limit 1 offset 2"
      Reader.Value = Cmd.ExecuteReader 
    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
  10. Erel

    Erel Administrator Staff Member Licensed User

    cmd.CommandText is a simple string:
    cmd.CommandText = "Select Alti.* from Alti Limit 1 offset " & Variable
  11. BerndB

    BerndB Member Licensed User

    ah, great!
    and quite simple

    Thank you erel!
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice