Results 1 to 9 of 9

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

  1. #1
    Hyperactive Member
    Join Date
    Apr 08
    Posts
    312

    Question 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

  2. #2
    Frenzied Member
    Join Date
    Sep 06
    Location
    Scotland
    Posts
    1,054

    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

  3. #3
    Hyperactive Member
    Join Date
    Apr 08
    Posts
    312

    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. #4
    Frenzied Member
    Join Date
    Sep 06
    Location
    Scotland
    Posts
    1,054

    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. #5
    Hyperactive Member
    Join Date
    Apr 08
    Posts
    312

    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. #6
    PowerPoster JuggaloBrotha's Avatar
    Join Date
    Sep 05
    Location
    Lansing, MI; USA
    Posts
    3,786

    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.
    Currently using: VS 2010 Ultimate on Win7 Ultimate x64.



    CodeBank: All Threads • Colors ComboBox • Fading & Gradient Form • MoveItemListBox/MoveItemListView • MultilineListBox • MenuButton • ToolStripCheckBox • Start with Windows

  7. #7
    New Member
    Join Date
    Aug 12
    Posts
    3

    Thumbs up 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.

  8. #8
    PowerPoster JuggaloBrotha's Avatar
    Join Date
    Sep 05
    Location
    Lansing, MI; USA
    Posts
    3,786

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

    Quote Originally Posted by brianvail51 View Post
    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
    Currently using: VS 2010 Ultimate on Win7 Ultimate x64.



    CodeBank: All Threads • Colors ComboBox • Fading & Gradient Form • MoveItemListBox/MoveItemListView • MultilineListBox • MenuButton • ToolStripCheckBox • Start with Windows

  9. #9
    New Member
    Join Date
    Aug 12
    Posts
    3

    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
  •