I'm trying to make a button called "Save" which saves all of the information entered into the textboxes as a .txt document. I'm very notice in this language and I don't know how to do it.
IO.File.WriteAllText
^ That's what I have now.
I'm trying to make a button called "Save" which saves all of the information entered into the textboxes as a .txt document. I'm very notice in this language and I don't know how to do it.
IO.File.WriteAllText
^ That's what I have now.
What exactly do you not understand about the examples of File.WriteAllText that you found on the web? I just Googled and the first result was the MSDN documentation, which is what everyone should read first anyway.
http://msdn.microsoft.com/en-us/library/ms143375.aspx
That includes, amongst other information, a code example. Is there anything in that you're not clear about?
2007-2013
Why is my data not saved to my database? | Communicating between multiple forms | MSDN Data Walkthroughs
MSDN "How Do I?" Videos: VB | C#
VBForums Database Development FAQ
My CodeBank Submissions: VB (*NEW* Pausing Code) | C#
My Blog: Using Parameters in ADO.NET | Keyboard Events | Assemblies & Namespaces
try this:
vb Code:
Public Class Form1 Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click 'save IO.File.WriteAllLines("c:\example.txt", New String() {TextBox1.Text, TextBox2.Text, TextBox3.Text}) End Sub Private Sub btnOpen_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOpen.Click 'open Dim lines() As String = IO.File.ReadAllLines("c:\example.txt") If lines.Length <> 3 Then Return TextBox1.Text = lines(0) TextBox2.Text = lines(1) TextBox3.Text = lines(2) End Sub End Class
![]()
![]()
if this helps, rate me
![]()
![]()
irregular regions | numericTextbox | keycodes | removing control properties | hotkeys | rtf printing | Extended RichTextBox | iconWorks | readonly listbox | sort listview | screen capture | relational listForms | countDown timer | animated notifyIcon form | dynamic crystal report | move / resize runtime controls | reOrderable DnD listview / listbox | self closing message box | searchable list(of class) | cursor from bitmap | (VB2008+) Textbox - GetFirstVisibleLineIndex / GetLastVisibleLineIndex | vb2008 extensions | Paint lite.Net | calculator | inline calculator | export listview to word table | imperial~metric converter | export DGV to word ~ excel | globalInputHook | dropDown Calendar control | International Time + Currency | GDI+ gauge | quizControl | extended dgv
My Web Site....
Maths Revision V1.0
Play Connect4 against your PC (java Applet)
Ah, I missed that it was TextBoxes rather than TextBox. My apologies.
2007-2013
Why is my data not saved to my database? | Communicating between multiple forms | MSDN Data Walkthroughs
MSDN "How Do I?" Videos: VB | C#
VBForums Database Development FAQ
My CodeBank Submissions: VB (*NEW* Pausing Code) | C#
My Blog: Using Parameters in ADO.NET | Keyboard Events | Assemblies & Namespaces
The code works sort've. What would I put for c:\example.txt If I just want it to open up the save dialog box as a .txt document on anyones computer.
vb Code:
Public Class Form1 Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click 'save Dim sfd As New SaveFileDialog With { _ .Title = "Choose file to save to", _ .Filter = "TXT (*.txt)|*.txt|All Files (*.*)|*.*", _ .FilterIndex = 0} if sfd.showdialog = dialogresult.ok then IO.File.WriteAllLines(sfd.filename, New String() {TextBox1.Text, TextBox2.Text, TextBox3.Text}) end if End Sub Private Sub btnOpen_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOpen.Click 'open Dim ofd As New OpenFileDialog With { _ .Title = "Choose file to open", _ .Filter = "TXT (*.txt)|*.txt|All Files (*.*)|*.*", _ .FilterIndex = 0} if ofd.showdialog = dialogresult.ok then Dim lines() As String = IO.File.ReadAllLines(ofd.filename) If lines.Length <> 3 Then Return TextBox1.Text = lines(0) TextBox2.Text = lines(1) TextBox3.Text = lines(2) end if End Sub End Class
![]()
![]()
if this helps, rate me
![]()
![]()
irregular regions | numericTextbox | keycodes | removing control properties | hotkeys | rtf printing | Extended RichTextBox | iconWorks | readonly listbox | sort listview | screen capture | relational listForms | countDown timer | animated notifyIcon form | dynamic crystal report | move / resize runtime controls | reOrderable DnD listview / listbox | self closing message box | searchable list(of class) | cursor from bitmap | (VB2008+) Textbox - GetFirstVisibleLineIndex / GetLastVisibleLineIndex | vb2008 extensions | Paint lite.Net | calculator | inline calculator | export listview to word table | imperial~metric converter | export DGV to word ~ excel | globalInputHook | dropDown Calendar control | International Time + Currency | GDI+ gauge | quizControl | extended dgv
My Web Site....
Maths Revision V1.0
Play Connect4 against your PC (java Applet)
![]()
![]()
if this helps, rate me
![]()
![]()
irregular regions | numericTextbox | keycodes | removing control properties | hotkeys | rtf printing | Extended RichTextBox | iconWorks | readonly listbox | sort listview | screen capture | relational listForms | countDown timer | animated notifyIcon form | dynamic crystal report | move / resize runtime controls | reOrderable DnD listview / listbox | self closing message box | searchable list(of class) | cursor from bitmap | (VB2008+) Textbox - GetFirstVisibleLineIndex / GetLastVisibleLineIndex | vb2008 extensions | Paint lite.Net | calculator | inline calculator | export listview to word table | imperial~metric converter | export DGV to word ~ excel | globalInputHook | dropDown Calendar control | International Time + Currency | GDI+ gauge | quizControl | extended dgv
My Web Site....
Maths Revision V1.0
Play Connect4 against your PC (java Applet)
Last edited by Hilt; May 26th, 2012 at 09:10 AM.
Still have no clue what I'm doing, can anyone give me some insight?
post #6 is the working code.
![]()
![]()
if this helps, rate me
![]()
![]()
irregular regions | numericTextbox | keycodes | removing control properties | hotkeys | rtf printing | Extended RichTextBox | iconWorks | readonly listbox | sort listview | screen capture | relational listForms | countDown timer | animated notifyIcon form | dynamic crystal report | move / resize runtime controls | reOrderable DnD listview / listbox | self closing message box | searchable list(of class) | cursor from bitmap | (VB2008+) Textbox - GetFirstVisibleLineIndex / GetLastVisibleLineIndex | vb2008 extensions | Paint lite.Net | calculator | inline calculator | export listview to word table | imperial~metric converter | export DGV to word ~ excel | globalInputHook | dropDown Calendar control | International Time + Currency | GDI+ gauge | quizControl | extended dgv
My Web Site....
Maths Revision V1.0
Play Connect4 against your PC (java Applet)