Results 1 to 17 of 17

Thread: [RESOLVED] if checkbox.checked = true then remamber data 4 eva

  1. #1

    Thread Starter
    Hyperactive Member JXDOS's Avatar
    Join Date
    Aug 2006
    Location
    Mars...
    Posts
    423

    if checkbox.checked = true then remamber data 4 eva

    hi
    well, i made a check box that remembers the username and password but it only remembers if the program isnt closed.
    i want it to remember the data even when the comp restarts..
    Last edited by JXDOS; Apr 16th, 2012 at 12:02 AM.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,344

    Re: if checkbox.checked = true then remamber data 4 eva

    The answer to your question will be different depending on your version. Please ALWAYS specify which version you're using. There are radio buttons provided for the purpose.

  3. #3

    Thread Starter
    Hyperactive Member JXDOS's Avatar
    Join Date
    Aug 2006
    Location
    Mars...
    Posts
    423

    Re: if checkbox.checked = true then remamber data 4 eva

    vb express 2005

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,344

    Re: if checkbox.checked = true then remamber data 4 eva

    Go to the Settings tab of the project properties. Create three new settings:

    UserName, String
    Password, String
    RememberCredentials, Boolean

    Now go to the form and select the CheckBox. Expand the (ApplicationSettings) section and select the Checked property. Click the drop-down button and select the RememberCredentials setting. Now all the saving and loading will be done automatically. Whatever the Checked property of the CheckBox is when you close the app will be what it is when it is next opened. Whenever a user logs in you save their credentials to the My.Settings.UserName and My.Settings.Password properties. When the application starts each time you just check the value of the My.Settings.RememberCredentials property and, if it's True, then get the credentials from the previously mentioned properties, e.g.
    VB Code:
    1. If my.Settings.RememberCredentials Then
    2.     MessageBox.Show(String.Format("Your user name is '{0}' and your password is '{1}'." My.Settings.UserName, My.Settings.Password))
    3. End If

  5. #5

    Thread Starter
    Hyperactive Member JXDOS's Avatar
    Join Date
    Aug 2006
    Location
    Mars...
    Posts
    423

    Re: if checkbox.checked = true then remamber data 4 eva

    how is the 2 strings remembered though?
    in the data bindings im not sure how to bind it to the string thing in the settings.

    the "My.Settings.UserName, My.Settings.Password" was just loaded as "" even when the box is checked.
    Last edited by JXDOS; Aug 7th, 2006 at 08:48 AM.

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,344

    Re: if checkbox.checked = true then remamber data 4 eva

    I think I must be posting in another language lately. Noone seems to want to actually read what I'm posting.
    Quote Originally Posted by jmcilhinney
    Whenever a user logs in you save their credentials to the My.Settings.UserName and My.Settings.Password properties.
    The values are remembered because YOU assign them to those properties. All the application settings are automatically saved to an XML file when the application is shut down and then loaded automatically when the applciation starts up. All you have to do is interact with the My.Settings object and leave the rest to the Framework.

  7. #7

    Thread Starter
    Hyperactive Member JXDOS's Avatar
    Join Date
    Aug 2006
    Location
    Mars...
    Posts
    423

    Re: if checkbox.checked = true then remamber data 4 eva

    um.. do u mean just restarting the program?

  8. #8
    Fanatic Member dom_stapleton's Avatar
    Join Date
    Sep 2005
    Location
    Leigh-on-Sea, UK
    Posts
    665

    Re: if checkbox.checked = true then remamber data 4 eva

    Quote Originally Posted by jmcilhinney
    All the application settings are automatically saved to an XML file when the application is shut down and then loaded automatically when the applciation starts up.
    ...that sounds like the program being restarted to me. What are you having a problem with?
    I use Microsoft Visual Basic 2008 Express Edition.

    If my post has been helpful, please rate it, unless you don't believe in Karma... which actually I don't!

    Resources:
    Visual Basic Tutorials (1, 2) | MSDN Library | Google | Krugle | Search Forums

    Free components:
    Windows Forms Components | XP Common Controls Library

  9. #9
    Junior Member Phantom Coder's Avatar
    Join Date
    Aug 2006
    Posts
    24

    Re: if checkbox.checked = true then remamber data 4 eva

    Quote Originally Posted by jmcilhinney
    I think I must be posting in another language lately. Noone seems to want to actually read what I'm posting.The values are remembered because YOU assign them to those properties. All the application settings are automatically saved to an XML file when the application is shut down and then loaded automatically when the applciation starts up. All you have to do is interact with the My.Settings object and leave the rest to the Framework.
    Ya I read what you write I think you been great help to me. I was going to suggest just to save the values in a XML file but I went and look up the things you told him and it seemed it automatically saves them ifd I read them right.

  10. #10
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,344

    Re: if checkbox.checked = true then remamber data 4 eva

    Let me try to make it clearer. When you create application settings an application config file is created for your app automatically. A config file is a special XML file that is stored in the same folder as your executable. If your app's executable is named "MyApp.exe" then the config file is named "MyApp.exe.config". When you create application settings with User scope, which is the default, sections of that config file are also saved to each user's ApplicationData folder, so each user has their own copy of the settings values. When your app starts, all the values from the config file are loaded automatically. When your app shuts down all the values from the config file are saved automatically by default. You don't have to do anything other than create the settings to make all that happen.

    Now, application settings are accessed in code through the My.Settings object. If you have created application settings named UserName, Password and RememberCredentials then you have automatically create the properties My.Settings.UserName, My.Settings.Password and My.Settings.RememberCredentials. These are properties exactly like any other properties that you use all the time, so you can set and get them just like you do any other properties.

    Application settings can also be bound to control properties through the Properties window. When you bind an application setting to a control property, the value of that setting is automatically loaded when your app starts up and automatically assigned to the control property. Whenever the value of the setting changes the value of the control property will change. Likewise, whenever the value of the control property changes the value of the setting will change. That's what it means to be bound. When your app shuts down, the last value of the control property is also the last value of the setting, and that value is automatically saved to the config file, where it sits safely, waiting to be used again the next time your app is run.

    All this means that you have very little work to do. You create the three settings as I said. You bind the Checked property of the CheckBox to the RememberCredentials setting and you get the saved credentials from UserName and Password settings when your app starts up and you assign the current credentials to the UserName and Password settings when you want them to be saved. Everything else is done automatically.

  11. #11

    Thread Starter
    Hyperactive Member JXDOS's Avatar
    Join Date
    Aug 2006
    Location
    Mars...
    Posts
    423

    Re: if checkbox.checked = true then remamber data 4 eva

    o.. i got it now..
    next time instad of typing so much u cud just say assign the textbox's property binding to the usernam as string setting....

  12. #12
    Fanatic Member dom_stapleton's Avatar
    Join Date
    Sep 2005
    Location
    Leigh-on-Sea, UK
    Posts
    665

    Re: if checkbox.checked = true then remamber data 4 eva

    Quote Originally Posted by JXDOS
    o.. i got it now..
    next time instad of typing so much u cud just say assign the textbox's property binding to the usernam as string setting....
    What's the point if you don't understand what it is you're doing?
    I use Microsoft Visual Basic 2008 Express Edition.

    If my post has been helpful, please rate it, unless you don't believe in Karma... which actually I don't!

    Resources:
    Visual Basic Tutorials (1, 2) | MSDN Library | Google | Krugle | Search Forums

    Free components:
    Windows Forms Components | XP Common Controls Library

  13. #13
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,344

    Re: [RESOLVED] if checkbox.checked = true then remamber data 4 eva

    I'll type a lot less next time. Don't worry about that.

  14. #14

    Thread Starter
    Hyperactive Member JXDOS's Avatar
    Join Date
    Aug 2006
    Location
    Mars...
    Posts
    423

    Re: [RESOLVED] if checkbox.checked = true then remamber data 4 eva

    is there a way to set an 'if' condition to the application settings?

  15. #15

    Thread Starter
    Hyperactive Member JXDOS's Avatar
    Join Date
    Aug 2006
    Location
    Mars...
    Posts
    423

    Re: [RESOLVED] if checkbox.checked = true then remamber data 4 eva

    Thanks for your help guys. Was looking back at my silly posts back then as reference just now. I have used it in several projects over the years with VS2005 and 2008, but VS 2010 seems to be running into a few problems with this. It doesn't seem to be storing this data (during debug) even though I have assigned them to the application settings which links to the data bindings and the actual text fields... Any suggestions?
    If my post has been helpful, please rate it!

  16. #16
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,344

    Re: [RESOLVED] if checkbox.checked = true then remamber data 4 eva

    Is it an upgraded project or was it new in 2010? What are the EXACT circumstances? Have you tried doing something similar in a new test project to isolate just that function and does it behave the same way?

  17. #17

    Thread Starter
    Hyperactive Member JXDOS's Avatar
    Join Date
    Aug 2006
    Location
    Mars...
    Posts
    423

    Re: [RESOLVED] if checkbox.checked = true then remamber data 4 eva

    Thanks for the suggestion. I did another isolated project and it is working. Must have something to do with me deleting the settings and reinstating them again later.


    OK. Works now. There were some references and objects that have been deleted/renamed without deleting the other, which was what caused the problem I think. Thanks for your help.
    Last edited by JXDOS; Apr 16th, 2012 at 12:37 AM.
    If my post has been helpful, please rate it!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width