Reading certain line/positon from txt file
Reading certain line/positon from txt file
Reading certain line/positon from txt file
Reading certain line/positon from txt file
Reading certain line/positon from txt file
Reading certain line/positon from txt file Reading certain line/positon from txt file Reading certain line/positon from txt file Reading certain line/positon from txt file Reading certain line/positon from txt file Reading certain line/positon from txt file Reading certain line/positon from txt file Reading certain line/positon from txt file
Reading certain line/positon from txt file Reading certain line/positon from txt file
Reading certain line/positon from txt file
Go Back  Xtreme Visual Basic Talk > > > Reading certain line/positon from txt file


Reply
 
Thread Tools Display Modes
  #1  
Old 08-14-2010, 07:47 PM
timbuck4 timbuck4 is offline
Newcomer
 
Join Date: Aug 2010
Posts: 3
Default Reading certain line/positon from txt file


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:
        Dim StreamToDisplay As StreamReader
        StreamToDisplay = New StreamReader("C:\testing\testfile.txt")
        TextBox1.Text = StreamToDisplay.ReadLine()
        StreamToDisplay.Close()
Currently it's reading the first line of text (which is "[username]"). I want it to read Joe Smith

Text file (testfile.txt) is attached
Attached Files
File Type: txt testfile.txt (62 Bytes, 5 views)
Reply With Quote
  #2  
Old 08-15-2010, 08:37 AM
AtmaWeapon's Avatar
AtmaWeaponReading certain line/positon from txt file AtmaWeapon is offline
Fabulous Florist

Forum Leader
* Guru *
 
Join Date: Feb 2004
Location: Austin, TX
Posts: 9,500
Default

Have you thought about the problem at all? We tend to put as much effort into our answers as you put into your question. Here's what your question looks like to me:

Quote:
Hi, <explanation of a basic file I/O program>. Here's my code:
<code that reads one line from a file>

I need code that reads more than one line.
Think about it. You have a line of code that reads a line from a file. You want the next line too. What might you do to get the code to read another line from the file?
__________________
.NET Resources
My FAQ threads | Tutor's Corner | Code Library
I would bet money 2/3 of .NET questions are already answered in one of these three places.
Reply With Quote
  #3  
Old 08-15-2010, 03:13 PM
timbuck4 timbuck4 is offline
Newcomer
 
Join Date: Aug 2010
Posts: 3
Default

Quote:
Originally Posted by AtmaWeapon View Post
Have you thought about the problem at all? We tend to put as much effort into our answers as you put into your question. Here's what your question looks like to me:


Think about it. You have a line of code that reads a line from a file. You want the next line too. What might you do to get the code to read another line from the file?
I must have miscommunicated. I don't want both lines of text to poplute that text box I have on my form (it should skip the first line of text and read the second line).

And yes I have tried to fiqure out the problem and I'm stuck. This is why I joined this forum to possibly have someone point me in the right direction.
Reply With Quote
  #4  
Old 08-15-2010, 03:32 PM
AtmaWeapon's Avatar
AtmaWeaponReading certain line/positon from txt file AtmaWeapon is offline
Fabulous Florist

Forum Leader
* Guru *
 
Join Date: Feb 2004
Location: Austin, TX
Posts: 9,500
Default

Ahh, but you've already said what you need to do!

Quote:
skip the first line of text and read the second line
If you call ReadLine() it reads a line. If you don't do anything with the string it returns, you have in effect skipped a line. So call it, then call it again.
__________________
.NET Resources
My FAQ threads | Tutor's Corner | Code Library
I would bet money 2/3 of .NET questions are already answered in one of these three places.
Reply With Quote
  #5  
Old 08-16-2010, 09:41 PM
timbuck4 timbuck4 is offline
Newcomer
 
Join Date: Aug 2010
Posts: 3
Default

Not sure how to do that. Stillreading the first line of the txt file.
Reply With Quote
  #6  
Old 08-16-2010, 10:07 PM
HQcool22's Avatar
HQcool22 HQcool22 is offline
Regular
 
Join Date: Jun 2009
Location: Oregon
Posts: 94
Default

look at your code and find ReadLine() then call that by itself once, then call it again with your textbox.
__________________
I know stuff!
Reply With Quote
  #7  
Old 08-17-2010, 08:38 AM
AtmaWeapon's Avatar
AtmaWeaponReading certain line/positon from txt file AtmaWeapon is offline
Fabulous Florist

Forum Leader
* Guru *
 
Join Date: Feb 2004
Location: Austin, TX
Posts: 9,500
Default

I'm going to give you the benefit of the doubt; I feel like I'm usually a little quick to assume that someone wants little more than a copy/paste solution. Nonetheless, you're going to have to *learn* if you want to extract information from me, so let's tell a story.

Once upon a time, there was a fair princess. She had eyes only for a brave, courageous prince and they spent many a day together walking through the enchanted forest and dreaming of their wedding day. Alas, her kingdom lay within the realm of influence of a terrible dragon, Redfang the Fierce. The day before the wedding, the princess disappeared. Suspicion fell on Redfang, since practically nothing bad happened in the kingdom unless he was involved. So the handsome prince set off to Redfang's cave to win his princess back.

"Oh man, how did you ever figure out it was me?", Redfang smirked and rolled his eyes as the prince approached. As the prince reached for his sword Redfang snarled, "Hey, touch that sword and I'll turn you to dust. You think I lived this long by fighting princes? We're going to do battle with a logic puzzle."

The prince indicated he'd like to hear the rules of this logic puzzle before abandoning traditional invincible hero vs. dragon combat strategy. Redfang laughed and spake:

"I will present you with three doors. Behind one door is a trap that shoots a poison arrow; the poison will paralyze you and kill you over the next three years. Or not; I might get bored with your anguish and eat you before then. Behind another is the cursed spirit of a terrible eldritch god who will transport you to a world with non-cartesian geometries and... well I'm not clear on what else happens there. He tried to get me to go once but it smelled dreadful and honestly I don't trust him that much. The third door--"

"That one has the princess!", the prince interrupted. Redfang looked annoyed, "Yea, behind the third door the Princess is playing Mario Kart with my kids. She's actually pretty good. Anyway, I'm going to let you ask me two questions. The answer to the first question is guaranteed to be irrelevant to which door you should open, assuming you prefer the princess to horrible death. The answer to the second question is guaranteed to be honest, I swear on the honor of the great Dragonlord (bless his claws.) After you ask the second question, you must open one of the three doors or swear on your honor to never return."

"So... that second question... can I ask which door--"

"YES NOW SHUT UP AND DON'T GIVE THE PUNCHLINE AWAY!"

"This seems pretty stupid, can't you just give me the princess?"

"But thou must!"

"Fine, fine", sighed the prince. "I accept your challenge."

Redfang clapped his hands and squealed with glee. "OK, first question!"

"Which door is the princess behind?"

"Basically BASIC was the first language I spoke in. I was telling Apple deuces just where they could PEEK and POKE in."

"Right. Now my second question, which door is the princess behind?"

"CURSE YOU! YOU FIGURED OUT THE LOGIC PUZZLE.", Redfang fumed. "Oh well, she's behind the second door, I'll open it myself since you probably don't trust me."

And they all lived happily ever after.

----

Like the prince, you are in a situation where you know what question you need to ask ("What is the next line in the file?") but you also know that the first answer will be incorrect. Knowing this, you should ask the question, ignore the first answer, then ask it again.

Now, with that explanation, see if you can fill in the blanks:
Code:
Dim input As New StreamReader("______")
input.R___L___()
TextBox1.Text = input.ReadLine()
input.Close()
__________________
.NET Resources
My FAQ threads | Tutor's Corner | Code Library
I would bet money 2/3 of .NET questions are already answered in one of these three places.
Reply With Quote
  #8  
Old 08-17-2010, 03:49 PM
snarfblam's Avatar
snarfblamReading certain line/positon from txt file snarfblam is offline
Senior Contributor

Forum Leader
* Expert *
 
Join Date: Apr 2005
Location: USA
Posts: 896
Default

This might sound like a stupid question, timbuck, but you never know. Clearly you understand that when you call ReadLine once you get the first line of the file. Do you understand what it will return the second time you call ReadLine?

Learning to program isn't about learning a set of tricks. It's about learning a thought process. That's why most users here refuse to give out simple answers to simple questions.

(Atma, I hope I'm not spoiling the adventure, I'm just trying to pin down what the fundamental misunderstanding is. You know we all have those moments where we overlook the glaringly-obvious solution.)
__________________
C# _VB.NET _
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Reading certain line/positon from txt file
Reading certain line/positon from txt file
Reading certain line/positon from txt file Reading certain line/positon from txt file
Reading certain line/positon from txt file
Reading certain line/positon from txt file
Reading certain line/positon from txt file Reading certain line/positon from txt file Reading certain line/positon from txt file Reading certain line/positon from txt file Reading certain line/positon from txt file Reading certain line/positon from txt file Reading certain line/positon from txt file
Reading certain line/positon from txt file
Reading certain line/positon from txt file
 
Reading certain line/positon from txt file
Reading certain line/positon from txt file
 
-->