How to move file pointer to the start point?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jslee99a
    New Member
    • Jul 2007
    • 2

    #1

    How to move file pointer to the start point?

    hello

    I use visual basic 6.0.

    I want to read file twice.

    First i read file then i don't know how to move the file pointer to the start point.
    i don't want to close file and reopen.

    example)
    Open InputFileName For Input As #1

    While Not EOF(1)
    Line Input #1, line
    ...
    Wend

    'move file pointer to the start point
    'i don't know this

    While Not EOF(1)
    Line Input #1, line
    ...
    Wend

    Close #1

    thanks for reading
  • cyberdaemon
    New Member
    • Jul 2007
    • 38

    #2
    out of curiosity, why do you need to read the file twice?

    Cyberdaemon

    Comment

    • jslee99a
      New Member
      • Jul 2007
      • 2

      #3
      Originally posted by cyberdaemon
      out of curiosity, why do you need to read the file twice?

      Cyberdaemon
      I'm developing a verifying program.

      for example ) test.txt, 1, 1, 1, "F", 5, 5, 6, "TT" ...

      test.txt : file name to verify

      1 : line number of the file
      1 : start offset of line
      1 : end offset of line
      "F" : compare data

      5 : line number of the file
      5 : start offset of line
      6 : end offset of line
      "TT" : compare data

      First i open test.txt file
      and search line
      and if "Mid (line, start offset, end offset) = compare data " is ture, then print true
      and repeat
      It's line number is not sorted
      It's the reason i read file repeatedly

      You have any other good idea?

      Tom Lee.

      Comment

      • Killer42
        Recognized Expert Expert
        • Oct 2006
        • 8429

        #4
        [CODE=vb]Seek #1, 1[/CODE]
        Pretty sure this is what you're looking for.

        Comment

        • Killer42
          Recognized Expert Expert
          • Oct 2006
          • 8429

          #5
          As for other ideas, there are probably plenty of things you could do. For one thing, even though the operating system does caching to avoid having to physically read the disk repeatedly, still file IO is fairly "expensive" . One way to get around this would be to load each line of the file into an array. You can either do this as you go through doing your comparison, or load it up at the start, all in one go, then just use the array instead of the file.

          On the other hand, if you're talking about a small file and speed is not a major concern, you could just close the file and reopen it to start reading again from the beginning. But the Seek will be better than that approach.

          Comment

          • cicorp
            New Member
            • Dec 2019
            • 1

            #6
            You da man Killer42!
            (Your suggestion worked for me too, and your high IQ is appreciated.)

            Comment

            Working...