How to save textbox text to notepad and save again a textbox text to add it into the same note pad? - vb.net

I want to save my textbox1.text in a notepad of my computer. And after saving that, I will save the next textbox1.text again. But I want it to be added to the same notepad. Anyone can help me on the code? Using VB net.
I have a one form with controls and all entries will be displayed on one textbox. I want to save that textbox but I don't know how.

You could use the File.AppendAllText method to save the text to a file:
Public Sub SaveTextToFile(FilePath As String, Text As String)
System.IO.File.AppendAllText(FilePath, Text)
End Sub
Here is an example of using the method:
SaveTextToFile("C:\New.txt", textBox1.Text)

Related

How to pull text from the selected TextBox on a Report? VBA

I have a Report (rptCourses) which contains 170 TextBoxes which contain Course names, pulled from an access Table (tblCourses). When the user clicks on one of the Course Name TextBoxes, a form (frmRateCourse) loads containing a TextBox (txtboxCourseTitle), essentially a header, which ideally would contain the Course Name of the selected Report TextBox.
My question is: How can I take the text from the selected Report Textbox and input that text into the loaded Form's TextBox?
I apologize if this question already exists! And thank you, in advance, for any assistance!
Easiest is to pass the string as OpenArgs.
Private Sub CourseName_Click()
DoCmd.OpenForm "frmRateCourse", OpenArgs:=Me.CourseName.Value
End Sub
and in frmRateCourse:
Private Sub Form_Open(Cancel As Integer)
Me.lbTitle.Caption = Nz(Me.OpenArgs, "<no Title>")
End Sub

Overload Clipboard.SetText VB.net 3.5 (or how to copy 3-4 text box conents at same time)

I have a form where I require user input and when the user presses the "generate" key it will copy all the data from the relevant text boxes to the clipboard for them to enter the data in an external application.
At the moment i can only find out how to get the function to copy one text box at a time, and not string them into a sentence.
Private Sub Notes_Click(sender As Object, e As EventArgs) Handles Notes.Click
My.Computer.Clipboard.SetText(TextBox1.Text, TextBox6.Text, TextBox5.Text, TextDataFormat.Text)
The problem is that the function can no be overloaded. Can someone please confirm the function i can use (or provide me a sample code) for how to copy all text box contents to the clipboard?
This is ALL on one form
The clipboard only accepts one text value at a time, so it's pretty clear why your overload won't work. If you need multiple values, concatenate them; if you need to keep them separately identifiable, put a separator character between them and parse them back out on the receiving end.
My.Computer.SetText(TextBox1.Text + TextBox2.Text + TextBox3.Text +...)

check if richtextbox contains textbox

I want to create a very simple login form is VB
All of the usernames are in a textfile on my webserver.
So first the program downloads that textfile with:
Dim wc As New WebClient()
Dim datawc.DownloadString("url.txt")
After that my program put the the text in a richbox with
RichTextBox1.Text = data
Then the programs checks if the text that is entered in the textbox is also in the richtextbox.
Now the problem is that if i fill in the textbox 1122, and in the richtextbox is 1133 that the program returns a correct response.
Sorry for my bad english
I just fixed it myself by using this condition
If data.Contains(TextBox1.Text) Then

How to save changes of a saved text file in VB.NET

I have a text editor that can open text files .txtand puts the text in a textbox. The user can also save the text to a .txt file.
How can the user save the changes of that text file that was saved recently?
Also, If the user opened a txt file how can the text editor change the text file to what the user changed?
Hope you understood that. Thanks in advance.
Since I don't know what you've done so far I will take this from the beginning...
For this you will need these components:
A SaveFileDialog
An OpenFileDialog
Three buttons (or menuitems), labeled: "Save", "Save As", "Open"
And I actually recommed using a RichTextBox instead of a regular TextBox.
.
To start, we put a variable in the code to know what file was saved before:
Dim LatestFile As String
Then, go to the properties of your Save- and OpenFileDialog and put this in the Filter field:
Text files (*.txt)|*.txt
Then you double-click the SaveFileDialog which should write the SaveFileDialog_FileOk event in your code. There you put:
LatestFile = SaveFileDialog1.FileName
RichTextBox1.SaveFile(SaveFileDialog1.FileName, RichTextBoxStreamType.PlainText)
And then double-click the OpenFileDialog, and enter this code:
LatestFile = OpenFileDialog1.FileName
RichTextBox1.LoadFile(OpenFileDialog1.FileName, RichTextBoxStreamType.PlainText)
And then for the buttons:
The "Open" button:
OpenFileDialog1.ShowDialog()
The "Save" button:
If Not LatestFile = "" Then
RichTextBox1.SaveFile(LatestFile, RichTextBoxStreamType.PlainText)
Else
SaveFileDialog1.ShowDialog()
End If
And the "Save As" button:
SaveFileDialog1.ShowDialog()
.
Hope this helps!
If I understood your question: you want your text editor application to detect changes that happened to the source text file that it is currently viewing to the user and if it detects a change, it should update its text box to display the latest file for the user.. am I right?
If that is the case, one way to do that is to use a Timer. Every time the timer tick event is triggered, you should check the date of the last modification to the file. If it is greater than the date that you have checked while opening the file for the first time, then the file had gone through some changes. Reload the file contents into the text box.
Another way (without using Timers) is to only check for the modification date once the application window is activated. Since the user will have to change the focus of the program to, say Notepad to do changes to the text file, then once the user returns focus to the Text Editor Application, use the Window Activate or Click event to check the file modification date.

Create OpenFileDialog when RichTextBox selected?

In my application, a list of fields is read from a database, and then rendered in a TabControlPage. Each field has a Control of a specific type, one of which is a RichTextBox.
What I need, is when the user selects the RichTextBox, an OpenFileDialog should appear, allowing the user to select a file. The RichTextBox should then display the full path + filename(eg. C:/files/excel/thing.xlsx) in the form of a hyperlink.
Currently, you can type in the path+filename into the RichTextBox and it will automatically be made into a hyperlink.
Any suggestions, or perhaps reference material you can give me?
You can attach something like this to the Enter event on your RichTextBox:
Dim dialog As New OpenFileDialog()
Dim result As DialogResult = dialog.ShowDialog()
If result = Windows.Forms.DialogResult.OK Then
RichTextBox1.Text = dialog.FileName
End If
This is not turning it into a hyperlink for me, but it sounds like you have that part handled?
edited as per Lars' comment.