Text box save / open ( vb.net 2008)-VBForums

# Thread: Text box save / open ( vb.net 2008)

1. ## 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

all help is apreshated

i wont forget to vote for for all helpers

2. ## 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
End Sub

End Class

3. ## 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

4. ## 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.

5. ## 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

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.

7. ## 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
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.

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
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

9. ## Re: Text box save / open ( vb.net 2008)

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
•