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
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)
Re: Self-Taught programmer in need of some basic help...
Quote:
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
Re: Self-Taught programmer in need of some basic help...
Awesome. Thank you guys so much.
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
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
Re: Self-Taught programmer in need of some basic help...
You need to try it to see ;) But yes it will.
Re: Self-Taught programmer in need of some basic help...
Thanks guys. I think I'm in business...!