[Help] My.Settings autosaves.

Posts 1–15 of 21 · Page 1 of 2
[Help] My.Settings autosaves.
ok i make a login thing an i made a checkbox for ppl to save there user name but it seems to auto save it when not checked an when it checked it still saves wtf lol heres the code i no is a problem bcz its not working right

Code:
 Private Sub UsernameTextBox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles UsernameTextBox.TextChanged
        If CheckBox1.Checked = False Then
            My.Settings.username = UsernameTextBox.Text
        Else
        End If
        If CheckBox1.Checked = True Then
            My.Settings.username = UsernameTextBox.Text
        End If
    End Sub

    Private Sub Loginform1_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
        My.Settings.Save()
    End Sub

    Private Sub Loginform1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        UsernameTextBox.Text = My.Settings.username
    End Sub
End Class
Code:
If CheckBox1.Checked = False Then
            My.Settings.username = UsernameTextBox.Text
        Else
There is the problem U have when it isnt checked Usernem = textbox1.text
So just edit that part!

Also Why dont Use more "clean" the if statament?
Code:
If CheckBox1.Checked = False Then
            ''What you want
        Else
            My.Settings.username = UsernameTextBox.Text
        End If
    End Sub
im new to vb so learning +rep
Is this solved or...
no bcz what he said didnt work it still auto saves it
Quote Originally Posted by pushdis15 View Post
no bcz what he said didnt work it still auto saves it
I think you should remove this code.
Private Sub Loginform1_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
My.Settings.Save()
End Sub


Code:
 Private Sub UsernameTextBox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles UsernameTextBox.TextChanged
        If CheckBox1.Checked = True Then
            My.Settings.username = UsernameTextBox.Text
        End If
    End Sub

    Private Sub Loginform1_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
        My.Settings.Save()
    End Sub

    Private Sub Loginform1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        UsernameTextBox.Text = My.Settings.username
    End Sub
End Class
Private Sub Loginform1_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
My.Settings.Save()
End Sub

See what I (you) did there? You're saving it when the form (aka. window) closes! Move it to a button click.
Code:
Private Sub Checkbox1_CheckChanged(args) 
    If Checkbox1.checked = true then
       My.Settings.Username = txtUsername.text
       My.Settings.cbChecked = True
    Else
       My.Settings.Username = ""
       My.Settings.cbChecked = False
    End if
End sub

Public sub Form1_FormClosing(args)
   My.Settings.Save
End sub

Public sub Form1_Load(args)
   If My.Settings.cbChecked = true then
      txtUsername.text = My.Settings.Username
   Else If My.Settings.cbChecked = False Then
      txtUsername.text = ""
   End if
End sub
Quote Originally Posted by Erinador View Post
Code:
Private Sub Checkbox1_CheckChanged(args) 
    If Checkbox1.checked = true then
       My.Settings.Username = txtUsername.text
       My.Settings.cbChecked = True
    Else
       My.Settings.Username = ""
       My.Settings.cbChecked = False
    End if
End sub

Public sub Form1_FormClosing(args)
   My.Settings.Save
End sub

Public sub Form1_Load(args)
   If My.Settings.cbChecked = true then
      txtUsername.text = My.Settings.Username
   Else If My.Settings.cbChecked = False Then
      txtUsername.text = ""
   End if
End sub
@pushdis15 That should work

a simple if statement will work

if that doesn't work then try this

Code:
'Load
if checkbox1.checked = true then
'Load settings
end if

'formclosing
if checkbox1.checked = true then
'save settings
end if
'that should work out
Quote Originally Posted by willrulz188 View Post
@pushdis15 That should work

a simple if statement will work

if that doesn't work then try this

Code:
'Load
if checkbox1.checked = true then
'Load settings
end if

'formclosing
if checkbox1.checked = true then
'save settings
end if
'that should work out
ya bro i will tryin later when i get from skool i dont get y it saves auto tho thnks

Edit:@willrulz188 tryed it an it didnt even save the username D:
Edit: already answered
Quote Originally Posted by willrulz188 View Post
Edit: already answered
how u figure that ? i dont know if u didnt read the post but i said they didnt work still saves auto D:
Omg Lets see
Code:
If Checkbox1.checkd = true then
my.settings.username = textbox1.text
else
msgbox("Error")
That MUST edit your settings then you must save it ..
Quote Originally Posted by pushdis15 View Post


how u figure that ? i dont know if u didnt read the post but i said they didnt work still saves auto D:
You may want to read my post T_T
Posts 1–15 of 21 · Page 1 of 2
This thread is closed for replies.

Tags for this Thread

None

Need help?