How to Save Simple Data?

quddusaliquddus

Active member
Joined
Nov 20, 2007
Messages
25
Programming Experience
Beginner
Hi all :),
I am a beginner vb.net programmer and am using VB.Net Express. I wanted to know how I could save data in VB.Net without using databases. So for example - I would be able to save a persons details when they first use the program and load the data next time they use the program.

The reason for me to do this is that the size of the data to save is so small and that I dont need it to be organised in any particular way.

Any help would be much appreciated. THANK YOU!

Regards
Q
 
you could use any of these files: Text, CSV, XML

I would use XML personally, it's structured very similarly to a DB but it's only a file.
 
The way i would do this, and there may be an easier way, is to use My.Settings.

In the Solution Explorer double click on My Project. The click on the Settings tab. In there you can create settings for whatever info you may need to store, like their name or birthday or whatever.

Then in your code, you'll just assign values to your settings. Here's some code to kind of show you how it would work:

VB.NET:
Public Class Form1

    Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
        'Assign the values in the textboxes to the settings
        My.Settings.strFirstName = Me.txtFirstName.Text
        My.Settings.strLastName = Me.txtLastName.Text
    End Sub

    Private Sub btnDisplay_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDisplay.Click
        'Display the values in the settings
        Me.txtFirstName.Text = My.Settings.strFirstName
        Me.txtLastName.Text = My.Settings.strLastName
    End Sub
End Class

On my form i have two text boxes, one for first name and one for last name, and two buttons, one to save the values and one to show them. You would type your name into the text boxes, then press the save button to save it to the settings. Then the next time you open the app you press the display button and it will display the values in the textboxes.

Hopefully this helped you :)
 
you could use any of these files: Text, CSV, XML

I would use XML personally, it's structured very similarly to a DB but it's only a file.

I was thinking about telling him to go that way, but I wasn't sure what exactly he meant by users details. If its just a few things I think it would make more sense to go with My.Settings
 
So then if you had an application on a computer, and you had four separate users, each with their own user account, when they logged into their accounts, the application would know who they were?
 
What it mean is, if you have a backcolor user setting and allow the user to change some color that is saved here, then each user will have its own backcolor that is saved between application runs. Separate configuration files are saved for each windows account.

You don't use user settings to get information about windows account, there is system.security namespace functionality for that.
 
Back
Top