I have a form, with a bunch of info. Name Number ect on different Text boxes. My question is how do i make it so if you hit the "Save" button it saves all that information to a excel spreadsheet or Txt file?
Printable View
I have a form, with a bunch of info. Name Number ect on different Text boxes. My question is how do i make it so if you hit the "Save" button it saves all that information to a excel spreadsheet or Txt file?
If you have a lot of TextBoxes you could also do;Code:Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles Button1.Click
SaveTextBoxText("YourFileName")
End Sub
Private Sub SaveTextBoxText(ByVal filename As String)
Dim w As New System.IO.StreamWriter(filename, False)
w.WriteLine(TextBox1.Text)
w.WriteLine(TextBox2.Text)
w.WriteLine(TextBox3.Text)
w.WriteLine(TextBox4.Text)
'etc...
w.Close()
End Sub
But beware that the order the textboxes are written may change if you rename them.Code:Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles Button1.Click
SaveTextBoxText("YourFileName")
End Sub
Private Sub SaveTextBoxText(ByVal filename As String)
Dim w As New System.IO.StreamWriter(filename, False)
For Each ctl As Control In Me.Controls
If ctl.GetType.ToString = "System.Windows.Forms.TextBox" Then
w.WriteLine("TextBox " & ctl.Name & " has text " & ctl.Text)
End If
Next
w.Close()
End Sub
I am not farmiliar with txt files myself but I happen to know about this tutorial. Follow this link : http://www.homeandlearn.co.uk/NET/vbNet.html And Find The Heading : "VB .NET Nine - Working with Text Files"
Hope this helps.