|
-
May 7th, 2008, 10:50 AM
#1
Thread Starter
Hyperactive Member
Text box save / open ( vb.net 2008)
Hi, i have a text box called textnote
what i want is so that when the program is loaded it re-treives the text from a text document called textbox.txt
and on program close it saves the text to the same text box
ive never worked with saving dialogs b4 and would like it if someone could tell me what code to use, and if possilbe where to put it in like a mini tuturial
ive looked about but cant find anything to help my needs
thanx in advance
all help is apreshated
i wont forget to vote for for all helpers
-
May 7th, 2008, 11:00 AM
#2
Frenzied Member
Re: Text box save / open ( vb.net 2008)
This will work for a basic one. Thats assuming that the file will always be in the same location.
Code:
Public Class Form1
Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
My.Computer.FileSystem.WriteAllText("C:\TextBox.txt", TextNote.Text, False)
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
TextNote.Text = My.Computer.FileSystem.ReadAllText("C:\TextBox.txt")
End Sub
End Class
-
May 7th, 2008, 11:09 AM
#3
Thread Starter
Hyperactive Member
Re: Text box save / open ( vb.net 2008)
cheers 03myersd, ive gave yo a good rating
one thing tho is that form1_loaad has been underlined in blu with a comment saying it has multiple defination with identical signatures
could you tell me how to fix it mate, cheers
-
May 7th, 2008, 11:10 AM
#4
Frenzied Member
Re: Text box save / open ( vb.net 2008)
Sounds like you have another piece of code which runs when the form loads. Just find that sub and add that line into it.
-
May 7th, 2008, 11:23 AM
#5
Thread Starter
Hyperactive Member
Re: Text box save / open ( vb.net 2008)
lol thanx, i looked through it twice b4 posting the comment to make shure i didint do just that then after your comment i looked through it again and found it
just one last question where you put C:\TextBox.txt as a location of the file, dose it have to be more specifc and is there location that i can put in that no matter where the file is it looks for it and finds it,
if i was to add a text file to the projec and make it locate the file from there and save the data to its location?
cheers
-
May 7th, 2008, 11:51 AM
#6
Re: Text box save / open ( vb.net 2008)
Using 03myersd's code, the file saved and loaded directly on drive C:
You could use an OpenFileDialog and SaveFileDialog respectively to save/open the file from any location.
-
Aug 22nd, 2012, 08:19 PM
#7
New Member
Re: Text box save / open ( vb.net 2008)
Regarding this code:
Public Class Form1
Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
My.Computer.FileSystem.WriteAllText("C:\TextBox.txt", TextNote.Text, False)
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
TextNote.Text = My.Computer.FileSystem.ReadAllText("C:\TextBox.txt")
End Sub
End Class
Instead of using C:\ to find the textbox.txt, how can you link that file to resources, and what would the code be?
Thanks.
-
Aug 23rd, 2012, 08:46 AM
#8
Re: Text box save / open ( vb.net 2008)
 Originally Posted by brianvail51
Regarding this code:
Public Class Form1
Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
My.Computer.FileSystem.WriteAllText("C:\TextBox.txt", TextNote.Text, False)
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
TextNote.Text = My.Computer.FileSystem.ReadAllText("C:\TextBox.txt")
End Sub
End Class
Instead of using C:\ to find the textbox.txt, how can you link that file to resources, and what would the code be?
Thanks.
You can extract a resource to any location you want, where are you wanting to extract your resource to?
Just be sure to mark the files as "Embedded Resource" and here's an article that explains how to extract them from your app:
Extract Resources To Folder (Visual Basic 2008) - VB.NET
-
Aug 23rd, 2012, 05:33 PM
#9
New Member
Re: Text box save / open ( vb.net 2008)
Like instead of:
My.Computer.FileSystem.WriteAllText("C:\Users\Brian.Brian-Laptop\Desktop\text.txt", TextNote.Text, False)
Use (My attempt, but it didn't work):
My.Resources.TextNote.WriteAllText("C:\Users\Brian.Brian-Laptop\Desktop\text.txt", TextNote.Text, False)
So instead of grabbing the TextNote.txt from the Desktop, it grabs it from the my.resources from the application.
My fault for not fully explaining.
Brian
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
|