|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
visual basic problemIn 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 Show quoteHide quote "veens-zevenhonderdvijf" <veens7zer***@hotmail.com> wrote in message news:12180tgqb8nauf3@corp.supernews.com... > 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 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 > How to read from a file a character that has the ascii-number 10 or 13. If the file is not too big, you can read it into a single string as shown > 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. 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 Hi Jan,
You can read a file with the streamreader as ReadToEnd http://msdn2.microsoft.com/en-us/library/system.io.streamreader.readtoend.aspx You can than search the file on any character including the Chr(10) and Chr(13) http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vblr7/html/vafctchr.asp I hope this helps, 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 Show quoteHide quote "veens-zevenhonderdvijf" <veens7zer***@hotmail.com> wrote in message news:12180tgqb8nauf3@corp.supernews.com... > 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
progress bar
Need some help with vb StatusStrip Control How to abort a WinForms apps with no main window [VB.NET] How to store/load XML schema internally... Fields in Access database returned in alphabetical order datagridview combo box ASP.NET, CSS, and Netscape 7.1 Fitting a character on a small button latency when loading forms Coding a TimeSpan |
|||||||||||||||||||||||