|
-
Feb 9th, 2012, 04:57 AM
#1
Thread Starter
Member
Self-Taught programmer in need of some basic help...
I'll start out by saying that I'm fairly comfortable programming in VB (2005) but, since I'm self-taught, I don't know the proper terminology for most things, so I apologize in advance if this is hard to understand.
Should be an easy question today: I have a fairly simple application and I now need to store some data to a .txt document. From what I read, it should be easy, but I can't seem to get it working right now.
If the file path of the text document was: C:\Program Files\Poop.txt, how could I write the value of a variable (let's say the variable is called "intAge") to this text document? The simplest way would be awesome.
Thank you in advance,
Cameron
-
Feb 9th, 2012, 05:18 AM
#2
Re: Self-Taught programmer in need of some basic help...
Thread moved from the 'VB6 and Earlier' forum to the 'VB.Net' (VB2002 and later) forum
This way is rather simple:
Code:
My.Computer.FileSystem.WriteAllText("C:\Program Files\Poop.txt", intAge.ToString, False, System.Text.Encoding.Default)
-
Feb 9th, 2012, 06:19 AM
#3
Re: Self-Taught programmer in need of some basic help...
 Originally Posted by cameronlanni
I'll start out by saying that I'm fairly comfortable programming in VB (2005) but, since I'm self-taught, I don't know the proper terminology for most things, so I apologize in advance if this is hard to understand.
Should be an easy question today: I have a fairly simple application and I now need to store some data to a .txt document. From what I read, it should be easy, but I can't seem to get it working right now.
If the file path of the text document was: C:\Program Files\Poop.txt, how could I write the value of a variable (let's say the variable is called "intAge") to this text document? The simplest way would be awesome.
Thank you in advance,
Cameron
Code:
Imports System.IO
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim writer As StreamWriter = New StreamWriter("C:\VBForums.txt", True)
writer.WriteLine("VBForums")
writer.Close()
End Sub
End Class
-
Feb 10th, 2012, 04:49 PM
#4
Thread Starter
Member
Re: Self-Taught programmer in need of some basic help...
Awesome. Thank you guys so much.
31337 joke of the day
Q: Why do they call HTML Hyper Text?
A: Too much Java!
-
Feb 14th, 2012, 05:46 PM
#5
Thread Starter
Member
New Question...
Instead of making a new post, I think I'll bump this one since this is all part of one larger question...
How would I then go back into that text document, check to see what word (or number) is on line...let's say Line 25? How could I store the contents of Line 25 to a variable or how could I reference the contents of Line 25 for something like an If/Then Statement or to change the text in a Text Box to the contents of Line 25?
Thanks again for all of your continuous help,
Cameron
-
Feb 14th, 2012, 05:55 PM
#6
Re: Self-Taught programmer in need of some basic help...
vb Code:
' If you wanted to get all the lines into an Array ' Dim lines() As String = IO.File.ReadAllLines("C:\MyFile.txt") ' To view line 25 you would reference index 24 (we start from 0) ' MessageBox.Show(Lines(24)) ' Here we create a variable by reading all lines into an array ' and referencing index 24. Line 25 Dim line As String = IO.File.ReadAllLines("C:\MyFile.txt")(24) Me.txtMyTextBox.Text = line
-
Feb 14th, 2012, 06:08 PM
#7
Thread Starter
Member
Re: Self-Taught programmer in need of some basic help...
Great.
So I could then do something like this?:
Code:
Dim line As String = IO.File.ReadAllLines("C:\MyFile.txt")(24)
If line = "UR A WINRAR" Then
'Carry Out Main Command
Else
'Carry Out Secondary Command
End If
31337 joke of the day
Q: Why do they call HTML Hyper Text?
A: Too much Java!
-
Feb 14th, 2012, 06:46 PM
#8
Re: Self-Taught programmer in need of some basic help...
You need to try it to see But yes it will.
-
Feb 16th, 2012, 12:43 PM
#9
Thread Starter
Member
Re: Self-Taught programmer in need of some basic help...
Thanks guys. I think I'm in business...!
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
|