Help! how do i get text from 2 textboxs to be saved to a text document?
im very new at this and im trying to make a program where a user types something into a text box and then hits save, which saves the strings into and exsisting word document and saves the text from the two textboxes. im still very new and caoont figure this out. thank you for the help.
so far i have
Private
Sub
btnsave_Click(ByVal
senderAs
System.Object,ByVal
eAs
System.EventArgs)Handles
btnsave.ClickDim
firstNameAs
String
Dim
lastNameAs
String
firstName = TextBox1.Text
lastName = TextBox2.Text
End
Sub
[1025 byte] By [
Dagger] at [2008-1-10]
Dagger,
Welcome to VB.NET development world! According to your question on saving string from the TextBox control, I would like to provide you the suggestions as follows:
1. There is a simple way to save the string in TextBox is to use My.Computer.FileSystem.WriteAllText("C:\save.doc", TextBox1.Text, False) statement in VB 2005. Just add this to the SaveButton click event. I tried this method, it works. Please pay more attention to the format of the string, I am using Word 2007, then open the Doc in UTF-8 can get my correct string format.
2. So if you are using TextBox control to save the content, it is better to save it to TXT files. The following thread with the answers provides a sample on the issue:
How do you save text from a textbox as a txt file
3. RichTextBox is the better choice on your question. RichTextBox control is used for displaying, entering, and manipulating text with formatting. The RichTextBox control does everything the TextBox control does, but it can also display fonts, colors, and links; load text and embedded images from a file; undo and redo editing operations; and find specified characters. The RichTextBox control is typically used to provide text manipulation and display features similar to word processing applications such as Microsoft Word. Like the TextBox control, the RichTextBox control can display scroll bars; but unlike the TextBox control, it displays both horizontal and vertical scrollbars by default and has additional scrollbar settings.
When you add the control on your form and make the instance name "rtb", then you can use any supported methods of RichTextBox control, the "not declared" shows that you have not that class on the current application. Just add one to stop this kind of problem.
The following article can help you to save the content of RichTextBox to Doc file using RichTextBox.SaveFile Method:
How to: Save Files with the Windows Forms RichTextBox Control
Code Snippet
Public Sub SaveFile()
' You should replace the bold file name in the
' sample below with a file name of your own choosing.
RichTextBox1.SaveFile(System.Environment.GetFolderPath _
(System.Environment.SpecialFolder.Personal) _
& "\<b>Testdoc.rtf</b>", _
RichTextBoxStreamType.RichNoOleObjs)
End Sub
Hope that can help you.