Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.basic.visual.misc > #588
| From | GS <gs@somewhere.net> |
|---|---|
| Newsgroups | comp.lang.basic.visual.misc |
| Subject | Re: EOF Marker |
| Date | 2012-01-03 13:04 -0500 |
| Organization | A noiseless patient Spider |
| Message-ID | <jdvfv1$rqc$1@dont-email.me> (permalink) |
| References | <VVDMq.171568$6J7.5729@newsfe08.ams2> |
Ivar explained : > Hi ALL > > Got a bit of code that reads a text file, looks something like this: > > Open FilePath For Input As #FileNum > Do Until EOF(FileNum) > Line Input #FileNum, LineStr > DoSomething > Loop > Close #FileNum > > Everything has been working well for a very long time until! > The loop will exit long before it gets to the EOF > I looked in the file using note pad, and there are some strange characters in > some of the text lines. not the normal readable stuff that is expected > How they got there is still a mystery. > The question is - is there a chr in a text file that will cause the Do Loop > to exit before the EOF > Each of the lines that cause the loop to exit contain '¬' or '' Could this > be the cause? > What to do if it happens again? > > Thanks for any replies > > Ivar This is typical of the types of text files created by computer controlled equipment. I'd post what I use to read files with binary characters thrown in but Auric's solution is pretty much the same as mine. I would suggest, though, that you separate the processing logic from the file reading so that you can convert the file reading code to a reusable function that either returns a string or an array of the lines. For your convenience I've posted my function below... Function GetTextFromFile(sFileName As String) As String ' Opens and reads the contents of a text file Dim iNum As Integer, bOpen As Boolean On Error GoTo ErrHandler iNum = FreeFile() 'Get the next file number 'Read the entire file Open sFileName For Binary Access Read As #iNum bOpen = True '//if we got here then file opened successfully GetTextFromFile = Space$(LOF(iNum)): Get iNum, , GetTextFromFile ErrHandler: If bOpen Then Close #iNum End Function '//GetTextFromFile() -- Garry Free usenet access at http://www.eternal-september.org ClassicVB Users Regroup! comp.lang.basic.visual.misc
Back to comp.lang.basic.visual.misc | Previous | Next — Previous in thread | Next in thread | Find similar
EOF Marker "Ivar" <ivar.ekstromer000@ntlworld.com> - 2012-01-03 14:04 +0000
Re: EOF Marker "Auric__" <not.my.real@email.address> - 2012-01-03 15:05 +0000
Re: EOF Marker "Ivar" <ivar.ekstromer000@ntlworld.com> - 2012-01-03 16:05 +0000
Re: EOF Marker GS <gs@somewhere.net> - 2012-01-03 13:04 -0500
Re: EOF Marker "Theo Tress" <rbk@online.de> - 2012-01-20 17:45 +0100
csiph-web