Results 1 to 7 of 7

Thread: Resetting Filecursor(?)

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Mar 2004
    Location
    Netherlands
    Posts
    27

    Resetting Filecursor(?)

    Hello all,

    I want to open a file through the FileOpen method, then read through all the lines, making a count for them with an integer and then I want to reset the cursor back to the beginning of the file. This is what my initial code looks like:

    Code:
     Dim FilePath As String
    Dim cntLines As Integer
    Dim strLine As String
    
    FileOpen(1, FilePath, OpenMode.Input)
    Do Until EOF(1)
    strLine = LineInput(1)
    cntLines += 1
    Loop
    Now after that, I want to NOT close the file, but reset the cursor back to the beginning of the file and read through the file AGAIN, only this time I use strLine to grab the data from it (txt file)

    Any suggestions on how to do this?

    Thanks in advance,
    c(_)
    *(^.^); c(_)

  2. #2
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    FileStream has Position method that sets the position where reading starts . You just need to set it to 0 .

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Mar 2004
    Location
    Netherlands
    Posts
    27
    Thank you for your reply.
    Sorry that my answer is this late, but it has been hectic here...

    Anyways, I'm trying to prevent using FileStream since this class has a wrong way of handling foreign characters such as î, è etc.
    I was hoping to do this with FileOpen, FileClose... Is there a way?

    Thanks in advance,
    c(_)
    *(^.^); c(_)

  4. #4
    Fanatic Member pax's Avatar
    Join Date
    Mar 2001
    Location
    Denmark
    Posts
    840
    Hi.

    The stream is not the one responsable for converting your characters wrong.
    I think your problem is with the ASCiiEncoding.GetString function.
    At least it's the case with danish ÆØÅ.
    You have to instantiate a new encoding based in the codepage you need. In danish I would use :
    VB Code:
    1. Dim Enc As System.Text.Encoding = System.Text.Encoding.GetEncoding(1252)
    2. MyString=EncGetString(MyBytes)

    You just have to replace the 1252 with the codepage of your language (or the language used to create the file).

    Then it should be ok.

    I hope this helps, cause a stream IS the best way to do what you want.
    I wish I could think of something witty to put in my sig...

    ...Currently using VS2013...

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Mar 2004
    Location
    Netherlands
    Posts
    27
    Thank you, I'll do that then.
    Does anyone know how to obtain these codes?
    It would be handy since I need to manipulate multiple country files (some files English, some French, some Dutch etc)

    Thanks in advance (again!)

    c(_)
    *(^.^); c(_)

  6. #6
    Fanatic Member pax's Avatar
    Join Date
    Mar 2001
    Location
    Denmark
    Posts
    840
    Hi.

    Go to Control Panel and open International.
    On the "General" tab press "Advanced"
    There you should see a list of codepages.

    Note: This is from a Win2000 but I guess it look pretty much the same in XP.
    I wish I could think of something witty to put in my sig...

    ...Currently using VS2013...

  7. #7

    Thread Starter
    Junior Member
    Join Date
    Mar 2004
    Location
    Netherlands
    Posts
    27
    Thanks!
    *(^.^); c(_)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width