Results 1 to 10 of 10

Thread: Rewinding ascii files

  1. #1

    Thread Starter
    vbuggy krtxmrtz's Avatar
    Join Date
    May 2002
    Location
    In a probability cloud
    Posts
    5,573

    Question Rewinding ascii files

    When you open a file for input and have read all the text lines till the end, is it possible to rewind to the beginning of the file? (I seem to recall there are "rewind" statements or similar in other programming languages)
    Do I really have to close the file and open it again?

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333
    I've never heard of a "rewind" programming command.

  3. #3
    I don't do your homework! opus's Avatar
    Join Date
    Jun 2000
    Location
    Good Old Europe
    Posts
    3,863
    You can read at each exact postion of a file, but that'S only possible in the binary mode. To use that you mut know the exact position of each variabel you want to read. If you are reading an text file (which would be a good reason to do use the ASCII mode) it's not possible.
    You're welcome to rate this post!
    If your problem is solved, please use the Mark thread as resolved button


    Wait, I'm too old to hurry!

  4. #4

    Thread Starter
    vbuggy krtxmrtz's Avatar
    Join Date
    May 2002
    Location
    In a probability cloud
    Posts
    5,573
    There was definitely a "rewind" (as such) command in an old version of Fortran I used long time ago on a Jurassic Vax/VMS machine from DEC.

  5. #5
    Fanatic Member arsmakman's Avatar
    Join Date
    Dec 2001
    Location
    Leiden, Netherlands.
    Posts
    719
    If you want to "Rewind" just close the file and open it again...

    Or is that not a solution?
    No matter how fool-proof your program is, there will always be a better fool.

    Was a post helpful to you? Rate it!

  6. #6

    Thread Starter
    vbuggy krtxmrtz's Avatar
    Join Date
    May 2002
    Location
    In a probability cloud
    Posts
    5,573
    Originally posted by arsmakman
    Or is that not a solution?
    It is, only it takes more statements

  7. #7
    Fanatic Member arsmakman's Avatar
    Join Date
    Dec 2001
    Location
    Leiden, Netherlands.
    Posts
    719
    Originally posted by krtxmrtz
    It is, only it takes more statements
    *sigh*
    No matter how fool-proof your program is, there will always be a better fool.

    Was a post helpful to you? Rate it!

  8. #8
    New Member
    Join Date
    Nov 2018
    Posts
    2

    Re: Rewinding ascii files

    just when you open à file in VB:


    Open f For Input As #1
    ...
    ReDim A(n)
    'i don't know to restart of the up started file in VB

    'we must close #1 unit
    Close(1)

    'and reopen

    Open f As For Input As #1

    ...
    Close(1)

    As well instead of in Fortran 90 it's most efficiently , so:

    OPEN(UNIT=u,FILE='inputcvs1.prn',STATUS='OLD',POSITION='REWIND',ACTION='READ',ACCESS='SEQUENTIAL',DE LIM='NONE')

    ! the statement go to the end of file and
    ! if you want rewind at the start of file you can with REWIND command

    REWIND
    ! at this point the cursor of file restart from start of file without to close the file

    ! to avoid inutility code in superfially for two once
    ! you can close the file one once after terminated your commands
    CLOSE(u)

    So , Fortran 90 it's the most competitive programming languages from alien technology in extraterrestrial bases.
    If somebody know a command in VB to rewinding the cursor in the sequentially file , i lissen him, welcome.


    Best regards
    ZOne 51 technology based

  9. #9
    New Member
    Join Date
    Nov 2018
    Posts
    2

    Re: Rewinding ascii files

    From the VB forum there is some anwers here : http://www.vbforums.com/showthread.p...-Seek-function
    -->
    You can set the position with Seek.

    VB Code:
    1.Dim ByteToGet As Byte

    2.

    3.Open "c:\test.txt" For Binary Access Read As #1

    4. Seek #1, 2

    5. Get #1, , ByteToGet

    6. Debug.Print ByteToGet

    7. Seek #1, 1

    8. Get #1, , ByteToGet

    9. Debug.Print ByteToGet

    10.Close #1


    Didn't test, hope it works
    If I am not mistaken, you can use seek in two ways.

    To read the current position, it accepts 1 parameter:
    pos = Seek #1

    To set the position it accepts 2 parameters, but is doesn't return a value:
    Seek #1, 0

    where the second parameter is the position to jump to.

    Probably MSDN has two different pages for Seek (just like it has for Date)

    I can't check it right now, because i am not behind a machine with VB6 at the moment, but this is what i remember from it.



    Best regards
    ZOne 51 technology based

  10. #10
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    10,915

    Re: Rewinding ascii files

    I'm sure they've been anxiously waiting 16 years for the answer.
    Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.

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