[HELP] Text file saving

Posts 18 of 8 · Page 1 of 1
[HELP] Text file saving
Lets say I type something in the textbox of my form so it can be the settings. And when I exit it will save as a text file. So whenever I open the program it uses the text file. Help would be greatly appreciated.
Google is your freind. I dont have time to give you some source now. sorry.
Add the following line to your Form_Load Event:

So it will look something like this:

[php]
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
textbox1.text = GetSetting(Application.ProductName, "Settings", "TXT", "")

End Sub[/php]

Now Add the following code to Form_Closing Event:

So it will look something like this:
[php] Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
SaveSetting(Application.ProductName, "Settings", "TXT", textbox1.text)
End Sub[/php]

This will save and restore your text
But mj, then you would need the code to open the txt file when the program opens. that code might be something like this:

Form1 or Form1_open...
Shell(c:/user/desktop/vb.txt)

Something like that, you will need to change the part on where the file is

hope that helps
Declare

Code:
dim path as string


path = Application.startuppath & "\test.txt"
Writing

Code:
dim strw as streamwriter

  strw = New StreamWriter(path)
   strw.Write(Textbox1.text)
   strw.Close()
Reading

Code:
dim strr as streamreader

if file.exists(path) Then
strr = New StreamReader(path)
   Textbox1.Text = strr.ReadToEnd()
   objDateiLeser.Close()
end if
Ok guys. I usually browse youtube for some VB codes.

so, I'll share what I had just found. ^^

Saving the contents of the textbox to .txt file :
Code:
        Dim Save As New SaveFileDialog
        Save.Filter = "Text Files (*.txt)|*.txt|ALL FILES (*.*)|*.*"
        Save.Title = "Save File"
        Save.CheckPathExists = True
        Save.ShowDialog(Me)
        Try
            My.Computer.FileSystem.WriteAllText(Save.FileName, TextBox1.Text, False)
        Catch ex As Exception
        End Try
Here is to open the notepad
Code:
        Dim Open As New OpenFileDialog
        Open.FileName = ("<File Location>")
        Dim RT As New System.IO.StreamReader(Open.FileName)
        TextBox1.Text = RT.ReadToEnd
So, If I want my program to open the notepad instantly, I put it in the Form like this
Code:
    Private Sub Form1_Load
        Dim Open As New OpenFileDialog
        Open.FileName = ("<File Location>")
        Dim RT As New System.IO.StreamReader(Open.FileName)
        TextBox1.Text = RT.ReadToEnd
    End Sub
Here are some examples.

Same Location
Code:
Program location -->> X:\Users\Nathanael789\Desktop
Notepad -->> X:\Users\Nathanael789\Desktop\Readme.txt

Code Will be : Open.FileName = ("Readme.txt")
Different Location
Code:
Program location -->> X:\Users\Nathanael789\Desktop
Notepad -->> C:\Users\Nathanael789\Documents\Readme.txt

Code will be : Open.Filename = ("C:\Users\Nathanael789\Documents\Readme.txt")

Credits to the name called "SimpleVBTutorials" in Youtube. ^^
there is alot easier way that i use. i would share but my vb will not open anything, sorry
We don't even know if he wants to load the text into a textbox(which he prolly wants to do) or anything else...mhm
Posts 18 of 8 · Page 1 of 1
This thread is closed for replies.

Similar Threads

Tags for this Thread

None

Need help?