473,385 Members | 1,606 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

visual basic problem

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
Mar 12 '06 #1
5 1099
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
"veens-zevenhonderdvijf" <ve**********@hotmail.com> wrote in message
news:12*************@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

Mar 12 '06 #2
> 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

Mar 12 '06 #3
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
Mar 12 '06 #4
Hi Jan,

You can read a file with the streamreader as ReadToEnd

http://msdn2.microsoft.com/en-us/lib...readtoend.aspx

You can than search the file on any character including the Chr(10) and
Chr(13)

http://msdn.microsoft.com/library/de...l/vafctchr.asp

I hope this helps,

Cor
Mar 12 '06 #5
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

"veens-zevenhonderdvijf" <ve**********@hotmail.com> wrote in message
news:12*************@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

Mar 12 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: John | last post by:
I have a problem, it's not with any code I have because... there is no code. When I run a blank visual basic 6 form, it opens up just fine. When I add a text box, a caption, and a button... it...
8
by: delete table with Visual Basic 6 | last post by:
Dear developer, I have an error message when I try to delete or drop Microsoft Access XP table with ADOX in Visual Basic 6. I use the ADOX.Catalog and ADOX.table to create and delete or drop table...
26
by: Bruno Jouhier [MVP] | last post by:
I'm currently experiencing a strange phenomenon: At my Office, Visual Studio takes a very long time to compile our solution (more than 1 minute for the first project). At home, Visual Studio...
2
by: frossberg | last post by:
Hello! I tried to install the Visual Basic.NET Resource Kit (http://msdn.microsoft.com/vbasic/vbrkit/) but obviously something went very wrong and now it sems impossible both to repair and to...
4
by: MikeB | last post by:
I've been all over the net with this question, I hope I've finally found a group where I can ask about Visual Basic 2005. I'm at uni and we're working with Visual Basic 2005. I have some books, ...
1
by: praful pathak | last post by:
i i am praful pathak,porbandar i want to develop my own cross tab report in visual basic 6 i know what developed query from ms access but how to coded in visual basic in designing time and how to...
4
by: sqlguy | last post by:
Why do we have to contact MS for a problem that has been with this compiler from at least the beta of VS 20005. I am so sick and tired of the 30 - 40 clicks it takes to dismiss VS when there is a...
97
by: Master Programmer | last post by:
An friend insider told me that VB is to be killled off within 18 months. I guess this makes sence now that C# is here. I believe it and am actualy surprised they ever even included it in VS 2003 in...
6
by: Salman | last post by:
I would like to know how I can distribute the application that I create with Visual C++ express edition. I checked the menu options to find a deploy option similar to the one found on the Visual...
1
by: Ronm | last post by:
Hey Guys, I have a problem which has been driving me crazy for the last days. I'm working on a small project involving: Visual Basic Acces Database ASP and adobe/macromedia Flash,
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.