|
-
Jan 3rd, 2010, 04:11 AM
#1
Thread Starter
Member
Write and Read txt Files
How can I make txt files and read them in VB2008? The text file does not just consist of one single line. But probably more than a single line.
How do I read the txt file and put each line in one variable.
For example, the txt file:
Code:
Jimmy
William
Steph
Stephen
Flo
And read it, putting each name in an array variable.
Thanks!
-
Jan 3rd, 2010, 06:45 AM
#2
Lively Member
Re: Write and Read txt Files
lol exact same thing i'm looking for.
can't sort it out yet. wish it was as easy as in php.
"Against All Odds"

-
Jan 3rd, 2010, 06:49 AM
#3
Re: Write and Read txt Files
Have either of you considered searching this forum or just doing a general google search?
There are literally hundreds of people have already asked the question on here and been given examples and help, and a google search using the keywords "reading and writing text files vb.net" returned 1.2 million pages.
-
Jan 3rd, 2010, 06:59 AM
#4
Lively Member
Re: Write and Read txt Files
It's like this
Dim line As New List(Of String)
line.AddRange(IO.File.OpenText("C:\hi.txt").ReadToEnd.Split(Environment.NewLine))
"Against All Odds"

-
Jan 3rd, 2010, 07:10 AM
#5
Thread Starter
Member
Re: Write and Read txt Files
Thx Choller, that one worked out.
@Paul
Yes, I've searched through Google and even YouTube. But all I find is to make one single file with one Line on it. Considering to search on this forum, I did found a lot of examples, but those examples does not fit to my use.
-
Jan 3rd, 2010, 07:15 AM
#6
Re: Write and Read txt Files
Yes, I've searched through Google and even YouTube. But all I find is to make one single file with one Line on it.
OK I went back to my google search using the keywords I described above, and looked at the first two results. Both showed explicitly how to create a text file and in both occasions showed examples of writing multiple lines of data. Even if they hadn't and you have an example showing you how to write one line of data it isn't exactly a huge leap to work out how to write two lines.
I'm not going to go through the other 1,209,998 pages returned in the results but I'm prepared to bet that most of them (if not all) would tell you exactly what you need to do.
-
Jan 3rd, 2010, 07:54 AM
#7
Lively Member
Re: Write and Read txt Files
To be honest I googled to and I couldn't find a really simple solution. Everything was wrapped around some piece of extra code and it wasn't easy to figure it out.
After coming back to this forum and using the search functions here I was able to find it.
"Against All Odds"

-
Jan 3rd, 2010, 08:13 AM
#8
New Member
Re: Write and Read txt Files
vb Code:
dim read as system.io.streamreader = my.computer.filesystem.opentextfilereader("C:/myfile.txt")
dim text = read.readtoend()
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|