I was wondering what is the easiest way to save and load data through different forms in vb. I just want to save 3 textbox.text that a user saves and be able to load it on a different form.
Select File > Save frmCounter As .... The Save Form As dialog box appears. The Save in: textbox shows the name of the folder where the form will be saved. You should create a new folder for this project.
You can use serialization to persist an object's data between instances, which enables you to store values and retrieve them the next time that the object is instantiated. In Visual Basic, to store simple data, such as a name or number, you can use the My. Settings object.
Drag and drop a button from the VB toolbox to the form in which you want to display the auto-save button. VS automatically draws the button, but use your mouse to set up the button size.
The simplest option would be to save them to a simple delimited text file. For instance, this would save the values in a pipe-delimited file:
File.WriteAllText("C:\Data.txt", String.Join("|", new String() {TextBox1.Text, TextBox2.Text, TextBox3.Text}))
And this would read it in:
Dim values() as String = File.ReadAllText("C:\Data.txt").Split("|"c)
TextBox1.Text = values(0)
TextBox2.Text = values(1)
TextBox3.Text = values(2)
However, it's not smart to save to a file in the root directory. The safest thing would be to store it in a file in Isolated Storage. Also, it would be even better to store it in XML. This could be easily done with serialization.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With