StreamReader - Reading Specific Line In Text File

Oct 15, 2011

I am currently writing a Login Script, and I am having trouble making StreamReader read a specific line in a text file. This is what I have so far (not the entire script, just the reader lines):
Dim path As String = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)
Dim file As String = (path + "LogDat.txt")
Dim sr As New IO.StreamReader(file)
Dim line1 As String = sr.ReadLine(1) '' Supposed to read line 1
Dim line4 As String = sr.ReadLine(4) '' Supposed to read line 4
Dim line9 As String = sr.ReadLine(9) '' Supposed to read line 9

View 2 Replies


ADVERTISEMENT

C# - Reading New Line From Text File Using StreamReader

Aug 24, 2011

What I have stored in my file is values related to an account. (Just testing, not going to be used commercially). What I need is to draw the values for the username and password, by going through each new line, but .peek() doesn't seem to work for me.

My block looks as such :
public string CheckAccount(string username, string password) {
StreamReader sr;
string filename = "H:\AccountInfo.txt";
string s;
string result = "";
[Code] .....
My code doesn't read from the 2nd line onwards, it just hangs.

View 4 Replies

Streamreader Reading A Specific Line?

Mar 24, 2009

i need to read a specific line of txt in a filelines 1 and 3 always stay the same ...ishline 2 will change from time to timeits line 2 i need to readi can, using seekorigin cutout line 1 "highlighted", but i want to get rid of line 3 aswellis there a way of just reading line 2? even though it could be 5 words long or 5000?heres what i have so far

Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Dim fs As FileStream

[code]....

View 2 Replies

Reading A Specific Line In A Text File?

Nov 28, 2011

I have been learning VB for about 3 months now at college and decided to enhance my skills by making my own project at home. My project is basically a game where you have to guess if the next number will be higher or lower than the previous version and you can place bets on it. I have done all of this ok but I wanted to create a high score system so that you could save your score.I can manage to write out to a text file ok so that it looks like this

Highscores
Name
Score

[code]....

etc. But I am not sure on how to read in a specific line. So for example I want lblHighscore1.text to equal line 3 of the text document (as vb counts the first line as 0) So far all I have is this;

Dim objReader As IO.StreamReader = New IO.StreamReader("C:UsersKarlDesktopHighScore.t xt")
lblHighscore1.Text = (objReader.ReadLine)

View 3 Replies

Reading A Specific Line From A Text File And Displaying It In Individual Text Boxes?

Feb 16, 2010

I've been writing a weight program for flooded pressure vessels and I'm having trouble retrieving the data from the text files I've been saving. I know how to write the data to the text file, but retrieving it with OpenFileDialog is not so easy for me.The user has individual text boxes that they input strings or numbers into and when they save the file, each text box input is written to one line in the text file. For example, the first text box is for the username, therefore the first line of text that is saved is the person's name, the second text box is the customer, thus the second line in the text file is the customer name, and so on.

(Actually, the first line of text in the saved file designates whether English units were used or Metric units because when the user retrieves the saved file, English units will open one form and Metric units will open a separate form, so some If...Then statement will need to occur).I need to be able to read the first line, have either my "EnglishForm"form open or my "MetricForm" form open, and then have each subsequent line of text be displayed in their corresponding text boxes. I know I need to use ReadLine or LineInput, but I don't have a clue what to do.Assuming the syntax I've displayed below would just magically work (if only life were that easy), it would look something like this

If FirstLineOfTextInFile = "English" Then
EnglishForm.Show()
ElseIf FirstLineOfTextInFile = "Metric" Then[code]....

And so on...I read a lot of articles from the MSDN library and exhausted each link that I've looked through from Google and Bing, but most only retrieve data from the file to a single text box through some loop or streamreader and don't take into account multiple forms.

View 17 Replies

Streamreader - Text File - To Read Into A Listview - Read From A Specific Line In That File

Mar 11, 2010

I have a txt file that I need to read into a listview, but I need to read from a specific line in that file. Below is a sample of the txt file to read,

6400,3200,2,95.5,84,76.6,0
1,2,-20,15,0,0,0,"NO",0,0
TOTAL GPM= 6400 HWT= 95.5 CWT= 84.0 IWBT= 76.6 ALTITUDE= 0

CODE]...

View 1 Replies

StreamReader Not Reading To End Of Text File?

Jan 6, 2011

I'm trying to read through a large text file using StreamReader using the following code

Dim Fs As FileStream = New FileStream(Filename, FileMode.OpenOrCreate, FileAccess.Read, FileShare.Read)
Dim sr As New StreamReader(Fs)
Dim Line As String = ""

[Code]...

The process reads through the file and then exits the loop while only a third of the way through the file.What can I do to ensure it reads the whole file?

View 2 Replies

VS 2008 StreamReader Reading Certain Lines From Text File

Aug 15, 2010

I am in the process (slow process) if learning vb.net by trying to create a simple application that will read and write (save) chosen information to a text file. The application has text boxes (name, email address, etc) and I want to read information from certain lines in the text and place in the given text box.[code]When I start debugging mode it does not display the text until I click onto the text box and it's displaying the first line of text in the file. How do I skip the first line of text and have it display the second line (or the 6th, 24, or whatever line I need to be displayed)?Then I can start working on learning to use streamwriter

View 6 Replies

Streamreader Reading Specific Lines?

May 17, 2010

when using stream reader to read text files how would i go about reading or referencing specific lines.so if i wanted to read from say line 2, 3, 4 or 10,11,12 in the textfile or what ever.

View 7 Replies

Asp.net - StreamReader ReadLine Is Reading Every Other Line?

May 2, 2012

I am looping through a text file and reading and then parsing each line.. then, inserting into a sql server. The problem is, I am getting every other line. Any thoughts? I read another post on here that is similar and it says that that person was calling the ReadLine twice... which makes sense. I just cannot spot where it is happening.

Private Sub btnUpdateRSR_Click(sender As System.Object, e As System.EventArgs) Handles btnUpdateRSR.Click
' Get RSR File
lblStatus.Text = "Getting RSR File"
Application.DoEvents()

[code]....

View 3 Replies

Get StreamReader.ReadBlock To Start At A Specific Line?

Dec 31, 2009

I want streamreader.Readblock to start reading a file from a specific line, but I need some help with this.so far I have have the following example

[Code]...

View 4 Replies

Reading Text File Line By Line, With Resetting Position To Beginning Of File

Jun 23, 2011

I'm reading a text file with StreamReader, line by line. If a condition is met, then I do an operation and then start reading the file again from the first line. I realize I could close and then re-open the file, but surely this would be very slow.

I could do this easily in VB6, but pulling my hair out trying to do this in vB.net. It seems that 'Seek' is the function to use, but it doesn't work.

I've seen other examples, where it works, but you must open it a different way -- with a file number.

Imports System.IO
Dim I as Integer
Dim LineText as String

[Code].....

View 2 Replies

VS 2008 Reading Text File Line By Line - Put Into Text Boxes

Sep 21, 2009

Basically what I'm trying to do is read a text file line by line. After each line is read, it will put each line into a separate text box. I've been trying to do this for a while and so far I haven't been able to. I tried using a for loop, but that just put all my lines in to one textbox.

View 8 Replies

Reading An Editing A Text File, Line By Line

Sep 11, 2011

Basically, I'm creating an application which takes a list of words in .txt format, such like this:

Abc
Def
Ghi
Jkl
mno

What I want to be able to do is modify the words, one by one, so that I end with

Abc1
Def1
Ghi1
Jkl1
mno1

or whatever the user wants.

I created this app in C++ to get the logic, since I am more confident with that

View 4 Replies

Reading Text File Line By Line Into Array?

Mar 19, 2012

I must use streamreader to read text file line by line into array.

Here's what I've got.

Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Dim numbers() As Double = New StreamReader(txtfile.Text)
Dim numbersarray() As Double

[Code].....

View 10 Replies

VS 2010 : Reading Line By Line From A Text File?

Feb 13, 2012

the following code was to be entered to read each line of the file "line by line" It did not work for me as instructed and I am trying to understand why?

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim FILE_NAME As String = "C:UsersOwnerDocuments est.txt"
Dim objReader As New System.IO.StreamReader(FILE_NAME)
Dim TextLine As String

[code]....

View 9 Replies

StreamReader/Writer - Loads An Entire Text File Into A Streamreader Variable

Jul 9, 2009

I'm writing a program that basically loads an entire text file into a streamreader variable, then reads this variable line by line and parses and writes a line into a new text file. I'm VERY new and my knowledge is mostly self-taught, but I can't seem to get out of this one. It works for smaller files, but it appears to reach a limit in characters at some point because in a file of 900 lines, it stops writing about halfway through 800 and there are no errors, the program actually completes and the message box pops up.

There are a few things with this code I already know I should fix, such as creating the new text file name, it's messy, I just don't know how.

Private Sub btnProcess_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnProcess.Click
Dim IndexValues As String()

[CODE]...

View 10 Replies

Reading A Text File Line By Line?

Jul 28, 2011

i got vb to read the text file but it reads the whole thing and displays it on a text line,how can i make it so it reads it like 1 line at a time after every click,so if my text file is like this

hello
goodbye

then i dont want it to display both, i want it to display hello and if i click a button again then it displays goodbye?

View 8 Replies

Reading Text File Line By Line In .net?

Oct 31, 2010

i am doing program to read text file and fill the data to multi array , in my code i tried to read the first line of text file to array (here i used class) to save this data on it, because i will use it to read the another lines , files have the following format (all numbers are integers, all intra-line separators are spaces): First line: Number of events, number of rooms, number of features, number of students after the first line as u see we have 3 line have 10 which mean the One line for each room:Roomsize and after that the line which start from zeros and ones it format as:-

4 3 3 2
10
10

[code]....

View 2 Replies

Code For Downloading A File From Internet With A URL Line By Line With Streamreader?

Jan 20, 2010

show me a simple code for downloading a file from internet with a URL,Line by Line with streamreader?

View 6 Replies

Reading From Text File And Pulling Specific Rows?

Oct 15, 2011

I have a test.txt file that contains:

1/15/2011; somedescription ; Joe Blow ; $50
1/18/2011; somedescription ; John Doe ; $30
2/1/2011; somedescription; Joe Blow; $90

I want to be able to pull all rows of data associated with Joe Blow if a users selects Joe Blow from a combobox. In testing this out I added the code to a button

View 3 Replies

Reading/Writing Specific Lines Of A Text File?

Apr 21, 2009

I'm trying to create a program that stores a users stats for their character (for something like an RPG). I know how to write more than one line in a text file, but I want to learn how to read and write text on specific lines of my file. I know that you can just read each new line individually in order using a StreamReader, such as

username.text = readLine.ReadLine()
userage.text = readline.ReadLine()

[Code]....

This is good for just displaying the stats and changing them from a constant interface, but I'm afraid that eventually I'll need to read/write specific lines, like reading the fourth line which might specify magic level, or writing a new money amount.

View 4 Replies

Go To A Specific Line Of Text File Using .net?

Jun 8, 2011

I am reading a text file line by line using StreamReader.Readline(). After reading a line i have to check whether some fields of the line which is read are present in the rest of the file or not. What i am doing is that after reading a line from the file i am passing the streamreader to check whether there are multiple entries. i am trying to use line.Length() to get the length of line, so using this length i can go back to the line

my code:

Dim pos as Long
sr = File.OpenText(filepath)
While sr.Peek() <> -1

[code]....

my problem is that it is not giving me the expected line or it is skipping some part of the line.how can i return back to my line?

View 1 Replies

How To Go To A Specific Line Of Text File

Jul 26, 2011

i am reading a text file line by line using StreamReader.Readline(). After reading a line i have to check whether some fields of the line which is read are present in the rest of the file or not.What i am doing is that after reading a line from the file i am passing the streamreader to check whether there are multiple entries. i am trying to use line.Length() to get the length of line, so using this length i can go back to the line

my code:

Dim pos as Long

View 2 Replies

Reading Next Line Of Text File?

Sep 28, 2008

How do I make my program read the next line of a txt file instead the first line.

View 4 Replies

Reading The Last Line Of A Text File?

May 16, 2012

I've been trying to read the last line of a text file but the code i have done seem to be giving me errors, i'm not sure what i've done wrong.

Public Shared Function ReadLastLine(path As String, encoding As Encoding, newline As String) As [String]
Dim charsize As Integer = encoding.GetByteCount(vbLf)

[code].....

View 2 Replies

Extract Specific Line From Text File?

Aug 8, 2009

My text file look like this[code]...

I want to extract those lines according to value in ( ).

View 10 Replies

How To Replace Specific Line In Text File

Aug 12, 2009

I was wondering how I would go about replacing a specific line of text with different text, and then later reading a specific line of text (from the same file). The text file has a lot of lines, and basically the layout is like this:
Something1 Data I want to read
Something2 Data I want to read
Something3 Data I want to read
Each line has a specific word, and then after that word is the data I want to use for the form.

View 10 Replies

Overwrite Specific Line In Text File

Jan 12, 2010

How to read from a line in vb .net, I need to do the following:
change the line in a text file
[Path] = "c: hiscertainpath"
With this line
[Path] = "c: hatother
ewerpath"

These paths will most certainly be different lengths, so I need to either replace what's in the quotes or erase the line completely and enter a new one, but in the same spot, not appended to the end of the document.

View 5 Replies

Read Specific Line In A Text File

Jul 31, 2011

how I would read specific line in a text file.Is this possible, if not I would like to know so that I can make the extension in C#?

View 1 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved