473,418 Members | 5,099 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,418 software developers and data experts.

Problem reading text file

Hi everyone,

Do you know why the following code only read certain number of lines of text
file, but not the entire file?

Dim sr As StreamReader
Dim str As String
Dim al As ArrayList = New ArrayList
Do
str = sr.ReadLine
If str <> Nothing Then
al.Add(str)
End If
Loop Until str = Nothing

Thank you for your attention.

Nina

Nov 21 '05 #1
4 1513
"Nina" <Ni**@discussions.microsoft.com> schrieb:
Do you know why the following code only read certain number of lines of
text
file, but not the entire file?

Dim sr As StreamReader
Dim str As String
Dim al As ArrayList = New ArrayList
Do
str = sr.ReadLine
If str <> Nothing Then
'If str Is Nothing Then'.
al.Add(str)
End If
Loop Until str = Nothing


'Loop Until str Is Nothing'.

BTW:

Reading a text file line-by-line or blockwise with a progress indicator
<URL:http://dotnet.mvps.org/dotnet/faqs/?id=readfile&lang=en>

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #2
Thank you so much Mr. Wagner. I replaced "=" with "Is" as you suggested in
my code, and it worked. I'm curious why cannot use "=" here?

Nina

"Herfried K. Wagner [MVP]" wrote:
"Nina" <Ni**@discussions.microsoft.com> schrieb:
Do you know why the following code only read certain number of lines of
text
file, but not the entire file?

Dim sr As StreamReader
Dim str As String
Dim al As ArrayList = New ArrayList
Do
str = sr.ReadLine
If str <> Nothing Then


'If str Is Nothing Then'.
al.Add(str)
End If
Loop Until str = Nothing


'Loop Until str Is Nothing'.

BTW:

Reading a text file line-by-line or blockwise with a progress indicator
<URL:http://dotnet.mvps.org/dotnet/faqs/?id=readfile&lang=en>

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #3
"Nina" <Ni**@discussions.microsoft.com> schrieb:
Thank you so much Mr. Wagner. I replaced "=" with "Is" as you suggested
in
my code, and it worked. I'm curious why cannot use "=" here?


'=' doesn't check for reference equality, it checks values only. 'If Foo =
Nothing Then...' is the same as 'If Foo = "" Then...'. 'Nothing = ""'
returns 'True', 'Nothing Is ""' returns false. If an empty line is read,
the string read from the file is "", not 'Nothing'. When the end of the
file is reached, the string read from the file is 'Nothing', not "".

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #4
Thank you for your explanation and I got it.

Nina

"Herfried K. Wagner [MVP]" wrote:
"Nina" <Ni**@discussions.microsoft.com> schrieb:
Thank you so much Mr. Wagner. I replaced "=" with "Is" as you suggested
in
my code, and it worked. I'm curious why cannot use "=" here?


'=' doesn't check for reference equality, it checks values only. 'If Foo =
Nothing Then...' is the same as 'If Foo = "" Then...'. 'Nothing = ""'
returns 'True', 'Nothing Is ""' returns false. If an empty line is read,
the string read from the file is "", not 'Nothing'. When the end of the
file is reached, the string read from the file is 'Nothing', not "".

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #5

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

Similar topics

1
by: fabrice | last post by:
Hello, I've got trouble reading a text file (event viewer dump) by using the getline() function... After 200 - 300 lines that are read correctly, it suddenly stops reading the rest of the...
2
by: Sabin Finateanu | last post by:
Hi I'm having problem reading a file from my program and I think it's from a procedure I'm using but I don't see where I'm going wrong. Here is the code: public bool AllowUsage() { ...
0
by: Lokkju | last post by:
I am pretty much lost here - I am trying to create a managed c++ wrapper for this dll, so that I can use it from c#/vb.net, however, it does not conform to any standard style of coding I have seen....
2
by: Mad Scientist Jr | last post by:
i'm trying to read a file byte by byte (and later alter the data and write it to a 2nd file byte by byte) and running into a problem where it seems to keep reading the same byte over and over again...
5
by: Scott M. Lyon | last post by:
I've just discovered a bug in some code I wrote a little while ago, and I need you guys' help to fix it. My program imports data from a standard Excel Spreadsheet (just with specific column...
0
by: Fabrice | last post by:
Hello, (Alain) Tis is a part of my code to retrieve text from hastable in memory cache, by reading (befor) a resources file. Thanks for your help. /1/ The resources file * I have create a...
6
by: Bill Nguyen | last post by:
I'm reading a CSV file with the date colum formatted as "YYMMDD" -"070310" when viewed in notepad or similar trext editor. However, in my app, using ODBCReader, the column value becomes "70310"...
5
by: Neil Crighton | last post by:
I'm using the zipfile library to read a zip file in Windows, and it seems to be adding too many newlines to extracted files. I've found that for extracted text-encoded files, removing all instances...
1
by: stoogots2 | last post by:
I have written a Windows App in C# that needs to read a text file over the network, starting from the end of the file and reading backwards toward the beginning (looking for the last occurrence of a...
27
by: Jeff | last post by:
Im trying to figure out why I cant read back a binary file correctly. I have the following union: #define BITE_RECORD_LEN 12 typedef union { unsigned char byte; struct { unsigned char type;...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.