Results 1 to 2 of 2
  1. #1
    TheBest-1337's Avatar
    Join Date
    Sep 2010
    Gender
    male
    Posts
    35
    Reputation
    15
    Thanks
    38
    My Mood
    Goofy

    Smile [VB.NET Tut] Saving Settings With My.Settings

    You will need:

    VB 2008/2010 (I'm using 2010)
    2 Forms (A default form and a 2nd form)
    1 TextBox
    2 CheckBoxes
    1 Button
    Should look something like this:
    [img]https://g.image*********/0071/project_preview.png[/img]

    Edit Texts (NOT THE NAMES):

    CheckBox1 = Save Password!
    CheckBox2 = Show Password
    Button1 = Login

    Editing My.Settings:

    Go to Project > ProjectName Properties on the upper tabs.
    Now go to Settings on the left tabs.
    Make 3 settings.
    Make "password", "passwordsave", and "checkbox1save" WITHOUT THE QUOTES!
    The value of "password" should be "madebyblessing", value of "passwordsave" should be blank, and value of "checkbox1save" should be "False" WITHOUT THE QUOTES!
    Should look something like this:
    [img]https://j.image*********/0207/settings.png[/img]

    Now for codes:

    In Button1, put:
    Code:
    If TextBox1.Text = My.Settings.password = True Then ' If the value of TextBox1 is the same value as "password" then...
                Form2.Show() ' Form2 shows.
            ElseIf TextBox1.Text = My.Settings.password = False Then ' If the value of TextBox1 has the different value as "password" then...
                MessageBox.Show("Password is not correct!", "Password Invalid") ' A message box shows saying "Password is not correct!" and with the title "Password invalid".
            End If
    In CheckBox1, put:
    Code:
    If CheckBox1.Checked = True Then ' If CheckBox1 is checked then...
                My.Settings.passwordsave = TextBox1.Text ' The value of "passwordsave" is what you type in TextBox1.
                My.Settings.checkbox1save = "True" ' The value of "checkbox1save" is True.
            ElseIf CheckBox1.Checked = False Then ' If CheckBox1 is not checked then...
                My.Settings.passwordsave = "" ' The value of password is nothing.
                My.Settings.checkbox1save = "False" ' The value of "checkbox1save" is False.
            End If
    In CheckBox2, put:
    Code:
    If CheckBox2.Checked = True Then ' If CheckBox2 is checked then...
                TextBox1.PasswordChar = "" ' The password character is plain texts.
            ElseIf CheckBox2.Checked = False Then ' If CheckBox2 is not checked then...
                TextBox1.PasswordChar = "*" ' The password character is *****.
            End If
    In Form1_Load, put:
    Code:
    TextBox1.Text = My.Settings.passwordsave ' The value of TextBox1 is the same value as "passwordsave".
            CheckBox1.Checked = My.Settings.checkbox1save ' The value of checked True/False of CheckBox1 is the same value as "checkbox1save". So if the value of "checkbox1save" is False, then CheckBox1 won't be checked.
    And your done!
    All credits go to me, and I used to be Blessing, but I registered as TheBest-1337 in MPGH since Blessing was already taken
    Last edited by TheBest-1337; 02-26-2011 at 10:43 AM.

  2. #2
    Hassan's Avatar
    Join Date
    May 2010
    Gender
    male
    Location
    System.Threading.Tasks
    Posts
    4,764
    Reputation
    495
    Thanks
    2,133
    My Mood
    Dead
    Looks good. A little explanation would make it better. Anyways, thanks for the tutorial.