473,602 Members | 2,792 Online
Bytes | Software Development & Data Engineering Community
+ 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 1263

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

strLine=sr.Read Line()
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******** ********@TK2MSF TNGP14.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.Read Line()
Meelis


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

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

strLine=sr.Read Line()
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******** ********@TK2MSF TNGP14.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&la ng=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.tex t = 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
3783
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 non-printing)...in Windows you need the (0x0d 0x0a) pair, if you want a new-line in a text editor. What's the correct way to get this 2-byte sequence into a file? Thanks #include <iostream>
5
2085
by: syntax | last post by:
hi here is my test code include<stdio.h> #include<stdlib.h> int main() {
5
2035
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 connects to the desktop via ActiveSync then a separate thread is spawned. In addition to the main desktop app window I also have a Notification form that appears in the lower right of the screen and provides feedback to the user about what is...
1
1543
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 get it to recieve only one line of data, but the next one i send to it wont be printed like the 1st one. I had a listner running in a thread, does anyone have a simple listner code example that would show how to have a tcplistner thread running...
7
2529
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 (my textfile is delimeted by a | ) But I've got on problem remaining, below you can so two example rows out of the textfile: 560000||TS|alu dak|0000000067|P400|20|7101|401|0|0|0|0|||||N|J 560039||KM|"De Gaer":
0
7993
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
7920
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8401
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8054
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
6730
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
5867
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5440
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3900
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2418
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 we have to send another system

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.