![]() |
| ||
| 2008 Opening, editing and saving text files Hi all, I would like to be able to read data from a text file, be able to edit it and save the new edits to that file over writing the old ones. Dim FILE_NAME As String = "C:\cat4\text.txt" |
| ||
| Re: 2008 Opening, editing and saving text files And The Problem Is.....? |
| ||
| Re: 2008 Opening, editing and saving text files wow smelf1 you're just full of questions lately. :) |
| ||
| Re: 2008 Opening, editing and saving text files You have problem with saving/loading text files, right? I tested your save-code: Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Clickand the result was "C:\Documents and Settings\<user name>\My Documentsc:\cat4\text.txt"which obviously is not a valid file name, so the fixed code is Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Clickand when you read the file Dim FILE_NAME As String = My.Computer.FileSystem.SpecialDirectories.MyDocumentsYou may also want to check what else exists in the My-namespace. For example, If My.Computer.FileSystem.FileExists(FILE_NAME) Thenand TextLine = My.Computer.FileSystem.ReadAllText(FILE_NAME, System.Text.Encoding.Default)if you want to read a text file with a single line of code. |
| ||
| Re: 2008 Opening, editing and saving text files right i have it working now, but how do i read say the first line in a text file and put it into a richtextbox1, then read the second line and put it into richtextbox2 |
| ||
| Re: 2008 Opening, editing and saving text files Quote:
Ha ha yep, once i get going its hard to stop. I have the text file reading into a richtextbox and saving back if i edit it. Private Const _FILE_NAME As String = "C:\cat4\bannedwebsites.txt" |
| ||
| Re: 2008 Opening, editing and saving text files how do i put line 1 from a text file into richtextbox1 and line 2 from that text file into richtextbox2. Then if i edit either i can then save and overwrite the original |
| ||
| Re: 2008 Opening, editing and saving text files In that case I would read the file with System.IO.StreamReader Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.ClickNotice that the above code also merges and writes richtextboxes back to the text file, so you'll have to cut and paste that part to a separate procedure. You may also try My.Computer.FileSystem.ReadAllText to read the text file and then use Split method to get an array of lines. |
| All times are GMT -4. The time now is 7:24 pm. |
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC