Alternative 1: Iterate all controls of the form and write the text of all the
TextBox
es to a text file
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles Button1.Click
Dim StringBuilder1 As StringBuilder = New StringBuilder()
StringBuilder1.Append(DateTimePicker1.Value.ToLongDateString() & vbCrLf)
For Each Control1 As Control In Controls
If TypeOf Control1 Is TextBox Then
StringBuilder1.Append(DirectCast(Control1, TextBox).Text.Trim() & vbCrLf)
End If
Next
System.IO.File.WriteAllText(Application.StartupPath &
"\AllTextFile.txt", StringBuilder1.ToString())
End Sub
Alternative 2: Write the text of specified
TextBox
es to a text file
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles Button1.Click
Dim StringBuilder1 As StringBuilder = New StringBuilder()
StringBuilder1.Append(DateTimePicker1.Value.ToLongDateString() & vbCrLf)
StringBuilder1.Append(TextBox1.Text & vbcrlf)
StringBuilder1.Append(TextBox2.Text & vbcrlf)
StringBuilder1.Append(TextBox3.Text & vbcrlf)
System.IO.File.WriteAllText(Application.StartupPath &
"\AllTextFile.txt", StringBuilder1.ToString())
End Sub