visual basic problem

  • Thread starter Thread starter veens-zevenhonderdvijf
  • Start date Start date
V

veens-zevenhonderdvijf

Hi,

In the past year I've been working more and more with visual basic (VB)
and less with turbo pascal (TP). There is however one thing I have not
discovered how to do with VB that I could certainly do with TP:
How to read from a file a character that has the ascii-number 10 or 13.
VB just skips it when I use code like below. It sees it as the end of a
line but I want VB to read all characters.

Can anybody tell me how to do this?

Sub ReadTestFile()

Dim Counter as long
Dim Character (1 to 1000) as String * 1

Open "C:\TEST\test.dat" For Input As #1
Line Input #1, ReadString
Counter = 1

While Not( (Len(ReadString) = 0) or (Counter > 1000) )
Character(Counter) = Asc(Left(ReadString, 1))
ReadString = Right(InleesStr, Len(ReadString) - 1)
Counter = Counter + 1
Wend

end sub

regards: Jan Veenstra
 
Klopt, char 10/13 geven een regeleinde aan.
Voor het soort bestanden dat jij wilt lezen moet je 'm openen als binary, en
dan hoop ik dat je een vaste recordlengte hebt.

Hth,
Martin
 
How to read from a file a character that has the ascii-number 10 or 13.
VB just skips it when I use code like below. It sees it as the end of a
line but I want VB to read all characters.

If the file is not too big, you can read it into a single string as shown
below, and I think you will see a performance improvement over reading one
line at a time. The string will contain tabs, cr's, lf's, so you will have
to scan for your data:

Dim FileSpec As String = "whatever.xxx"
Dim s As String = ""
Dim reader As IO.StreamReader = Nothing
Try
reader = New IO.StreamReader(Filespec)
s = reader.ReadToEnd()
Catch ex As Exception
' up to you
Finally
If Not reader Is Nothing Then reader.Close()
End Try
 
Martin,

This is an international newsgroup. Although there are a lot of people
active in this newsgroup for whom English is not the first language, are the
by convention writing all here in English. An answer is not alone for the
one who ask the question, however this newsgroup is searched as well by a
many persons all over the world.

Thanks in advance.

Cor
 
Don't worry, I didn't use any faul language, but Cor is right, since this is
a public medium, all should be able to understand what's being said.

If your file isn't extremely big you can use the ReadAllBytes method of
My.Computer.FileSystem.

Another method is what MS refers to as a legacy method: open the file for
binary access and read exactly the number of bytes you need with the FileGet
statement. This last method gives you greater control over your operation.

Hth,
Martin
 
Back
Top