|
-
Oct 15th, 2002, 09:38 AM
#1
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?
-
Oct 15th, 2002, 10:03 AM
#2
I've never heard of a "rewind" programming command.
-
Oct 15th, 2002, 10:12 AM
#3
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!
-
Oct 15th, 2002, 10:13 AM
#4
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.
-
Oct 15th, 2002, 10:31 AM
#5
Fanatic Member
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!
-
Oct 15th, 2002, 11:07 AM
#6
Originally posted by arsmakman
Or is that not a solution?
It is, only it takes more statements
-
Oct 15th, 2002, 11:13 AM
#7
Fanatic Member
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!
-
Nov 24th, 2018, 01:39 PM
#8
New Member
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
-
Nov 24th, 2018, 02:17 PM
#9
New Member
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
-
Nov 24th, 2018, 04:30 PM
#10
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|