writing to a text document
Moderator: Moderators
well, i have this
with the imports, and it creates the document on a button click, which is good.
but when i add this
nothing goes to the text document
Code: Select all
Dim StreamWrite As New StreamWriter("bob.txt")but when i add this
Code: Select all
streamwrite.writeline(textbox1.text)-
jeffslot
- Portablizer Extraordinaire
- Posts: 853
- Joined: Wed Jun 01, 2005 6:26 am
- Location: PA
- Contact:
this is where we opened it.
I believe that the "False" is overwrite, change it to true for append.
You might want to note the file might have to already exists (not sure) for the initial append...
Jeff
Code: Select all
Dim sw As New StreamWriter("C:\TestOutput.txt", False) You might want to note the file might have to already exists (not sure) for the initial append...
Jeff
Ya, i put that as global, fixed it by putting it in the sub for the click
so, now that i can write lines, i need to write it to a new line each time. What i did was this
though all that does is write the most recent line of code with the value of intC at the end of it. Fix?
so, now that i can write lines, i need to write it to a new line each time. What i did was this
Code: Select all
Dim intC As Integer = 1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim StreamWrite As New StreamWriter("bob.txt", False)
Dim sb As New StringBuilder
Dim str As String
intC = intC + 1
str = TextBox1.Text
StreamWrite.NewLine = intC
StreamWrite.WriteLine(str)
StreamWrite.Close()
End Sub-
jeffslot
- Portablizer Extraordinaire
- Posts: 853
- Joined: Wed Jun 01, 2005 6:26 am
- Location: PA
- Contact:
maybe change
to
Code: Select all
Dim StreamWrite As New StreamWriter("bob.txt", False)Code: Select all
Dim StreamWrite As New StreamWriter("bob.txt", True)Ok, well i just put
which inserted a line return each click. Now could you teach me how to read lines? 
Code: Select all
streamreader.newline = vbcrlf-
jeffslot
- Portablizer Extraordinaire
- Posts: 853
- Joined: Wed Jun 01, 2005 6:26 am
- Location: PA
- Contact:
Well a streamreader is pretty easy to use also...
Code: Select all
Dim sr As New StreamReader("C:\Anyfile.txt")
While sr.Read
'Do something
End While
sr.Close()
sr.Dispose()-
jeffslot
- Portablizer Extraordinaire
- Posts: 853
- Joined: Wed Jun 01, 2005 6:26 am
- Location: PA
- Contact:
Ok, here is my last bit for tonight.
I think that you might be able to use a for next loop to read whatever line you want.
For instance if you are only interested in reading line number five, you'd only read the line if your counter is equal to the line number you want to read.
Good luck with your project & keep us posted!
Jeff
I think that you might be able to use a for next loop to read whatever line you want.
For instance if you are only interested in reading line number five, you'd only read the line if your counter is equal to the line number you want to read.
Good luck with your project & keep us posted!
Jeff
