473,480 Members | 1,515 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Question about reading text-files

Hi!

I'm trying to make something like this to work with VB.NET 2003...

Dim sr As StreamReader = New StreamReader("C:\MyFile.txt")
Dim strLine As String

While ((strLine = sr.ReadLine()) <> Nothing)
'// Doing something here
End While

....but can't get it to work. What's wrong with that?

I have studied some Java basic programming earlier, and in this case I'm
trying to make an idea from java code...

while ((strLine = br.readLine()) != null) // br = BufferedReader

....to convert to work using VB 2003.

--
Thanks in advance!

Mika
Dec 9 '05 #1
6 1258

Dim sr As StreamReader = New StreamReader("C:\MyFile.txt")
Dim strLine As String

strLine=sr.ReadLine()
While Not strLine Is Nothing
'//Do something here

input = sr.ReadLine()
End While
sr.Close()
Hope this helps!

Meelis

"Mika M" <ma***************@luukku.com> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
Hi!

I'm trying to make something like this to work with VB.NET 2003...

Dim sr As StreamReader = New StreamReader("C:\MyFile.txt")
Dim strLine As String

While ((strLine = sr.ReadLine()) <> Nothing)
'// Doing something here
End While

...but can't get it to work. What's wrong with that?

I have studied some Java basic programming earlier, and in this case I'm
trying to make an idea from java code...

while ((strLine = br.readLine()) != null) // br = BufferedReader

...to convert to work using VB 2003.

--
Thanks in advance!

Mika

Dec 9 '05 #2
Mika,

The most easiest one in this case

\\\
Dim sr As StreamReader = New StreamReader("C:\MyFile.txt")
Dim strLine As String = sr.readtoend
///
However set it in a try and catch block for if the file does not exist.
\\\
dim strLine as String
Try
strLine = sr.ReadToEnd
Catch ex
messagebox.show(ex.tostring) 'in a more decent way
End Try
///

I hope this helps,

Cor

Dec 9 '05 #3

sry
input = sr.ReadLine() must be strLine=sr.ReadLine()
Meelis


"Meelis Lilbok" <me***********@deltmar.ee> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...

Dim sr As StreamReader = New StreamReader("C:\MyFile.txt")
Dim strLine As String

strLine=sr.ReadLine()
While Not strLine Is Nothing
'//Do something here

input = sr.ReadLine()
End While
sr.Close()
Hope this helps!

Meelis

"Mika M" <ma***************@luukku.com> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
Hi!

I'm trying to make something like this to work with VB.NET 2003...

Dim sr As StreamReader = New StreamReader("C:\MyFile.txt")
Dim strLine As String

While ((strLine = sr.ReadLine()) <> Nothing)
'// Doing something here
End While

...but can't get it to work. What's wrong with that?

I have studied some Java basic programming earlier, and in this case I'm
trying to make an idea from java code...

while ((strLine = br.readLine()) != null) // br = BufferedReader

...to convert to work using VB 2003.

--
Thanks in advance!

Mika


Dec 9 '05 #4
Yes I know basic ways to read file. In fact I was just trying to join
reading line and checking if the last line was reached, to save code
lines because "simple is beautiful" in my mind :)

Obviously that's not possible when using VB.NET
--
Cor Ligthert [MVP] kirjoitti:
Mika,

The most easiest one in this case

\\\
Dim sr As StreamReader = New StreamReader("C:\MyFile.txt")
Dim strLine As String = sr.readtoend
///
However set it in a try and catch block for if the file does not exist.
\\\
dim strLine as String
Try
strLine = sr.ReadToEnd
Catch ex
messagebox.show(ex.tostring) 'in a more decent way
End Try
///

I hope this helps,

Cor

Dec 9 '05 #5
"Mika M" <ma***************@luukku.com> schrieb:
I'm trying to make something like this to work with VB.NET 2003...

Dim sr As StreamReader = New StreamReader("C:\MyFile.txt")
Dim strLine As String

While ((strLine = sr.ReadLine()) <> Nothing)
'// Doing something here
End While


The problem is that '=' is interpreted as comparison operator when being
used in the 'While' condition. Working solutions can be found here:

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://classicvb.org/petition/>

Dec 9 '05 #6
you could also try this way

Private sr as StreamReader = new StreamReader("C:\MyFile.txt")
do

me.textbox1.text = sr.readline()

loop while sr.peek > -1

--
-iwdu15
Dec 9 '05 #7

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

Similar topics

13
3769
by: J. Campbell | last post by:
I'm wanting to output a text header file in front of the data portion of an output file. However when I use "\n" or "endl" as end of line, it just puts a 0x0a in the file(which is...
5
2073
by: syntax | last post by:
hi here is my test code include<stdio.h> #include<stdlib.h> int main() {
5
2025
by: Robert W. | last post by:
I'm creating a WinForms app that will act as a companion (think administrator functionality) to a Pocket PC app. Generally the WinForms app works under just the UI thread. But if a Pocket PC...
1
1526
by: Brian Henry | last post by:
Hello, I was tring to learn socket's (being i never used them before) and have a simple question. I want to create a listner that will get any data recieved and print it out. I've been able to...
7
2514
by: Peter Proost | last post by:
Hi, I'm creating an import module to read data from old textfiles, run some calculations on them and save them to sql server. I've figured out how to do a select on textfile using a schema.ini file...
0
7084
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6739
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
6929
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
5337
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,...
1
4779
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
4481
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...
0
2995
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1300
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
563
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.