-1

I want to know how to take several textbox's (with value imputed from the user) and put them together to make one big block of text to turn into a .txt. I am specifically trying to make a guitar tab application.

I have already created the base design, but I need help saving it. I put a menustrip to save. When the user clicks it opens a form with a rich textbox.

My problem: I want it to take the textbox's, format them in a specific order, and add them to the rich textbox where they can later save as a .txt.

Feel free to ask any questions to clarify my situation. Thanks.

Trevor
  • 1,111
  • 2
  • 18
  • 30
l_theBoss
  • 3
  • 1

1 Answers1

1

Below is a code that stores all the textboxes data into a string variable and then the contents of that variable is assigned to the richtextbox. There are two buttons, one to send the textboxes data to the richtextbox and another to save it to a text file. I hope you find it useful.

Public Class Form1 Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

End Sub

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    Dim tbox As String = ""
    tbox &= TextBox1.Text & Environment.NewLine &
        TextBox2.Text & Environment.NewLine &
        TextBox3.Text & Environment.NewLine &
        TextBox4.Text & Environment.NewLine &
        TextBox5.Text
    RichTextBox1.Text = tbox
End Sub

Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
    SaveMyFile()
End Sub

Public Sub SaveMyFile()
    ' Create a SaveFileDialog to request a path and file name to save to.
    Dim saveFile1 As New SaveFileDialog()

    ' Initialize the SaveFileDialog to specify the RTF extension for the file.
    saveFile1.DefaultExt = "*.txt"
    saveFile1.Filter = "TXT Files|*.txt"

    ' Determine if the user selected a file name from the saveFileDialog.
    If (saveFile1.ShowDialog() = System.Windows.Forms.DialogResult.OK) _
        And (saveFile1.FileName.Length) > 0 Then

        ' Save the contents of the RichTextBox into the file.
        RichTextBox1.SaveFile(saveFile1.FileName,
            RichTextBoxStreamType.PlainText)
    End If
End Sub

End Class