Results 1 to 9 of 9

Thread: [RESOLVED] Remembering Settings

  1. #1

    Thread Starter
    Lively Member Brinith's Avatar
    Join Date
    Feb 2012
    Location
    Near you
    Posts
    116

    Resolved [RESOLVED] Remembering Settings

    How do you make a program remember settings. For example, first it prompts you for your name, then when you close out of it and start it again, it will display your name?
    "When ideas and actions fuse, they form creations"

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

    Re: Remembering Settings

    Open the Settings page of the project properties and add a setting of the appropriate type with the appropriate name. You can then access that setting in code via the so-named property of My.Settings. Settings are automatically saved to the user config file at shutdown and loaded at startup. These settings are user-specific, so if you log into Windows as a different user then your app will have a different set of settings.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    9,017

    Re: Remembering Settings

    Use the Settings tab of project properties to create a setting and you can access it from code like:-
    vbnet Code:
    1. Dim uname As String = My.Settings.UserName
    The above is how you would access a setting named UserName created in the Settings tab.
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena

    Copy/move files using Windows Shell | I'm not wanted

    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. - jmcilhinney

    The threads I start are Niya and Olaf free zones. No arguing about the benefits of VB6 over .NET here please. Happiness must reign. - yereverluvinuncleber

  4. #4

    Thread Starter
    Lively Member Brinith's Avatar
    Join Date
    Feb 2012
    Location
    Near you
    Posts
    116

    Re: Remembering Settings

    I see, but to start it up, should it be like this?

    Name= My.Settings.Username
    Label1.Text = Name

    Sorry I am pretty much a complete beginner at programmer so Im probably way off.
    "When ideas and actions fuse, they form creations"

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Remembering Settings

    Quote Originally Posted by Brinith View Post
    I see, but to start it up, should it be like this?

    Name= My.Settings.Username
    Label1.Text = Name

    Sorry I am pretty much a complete beginner at programmer so Im probably way off.
    When you tried that, did it work?
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  6. #6

    Thread Starter
    Lively Member Brinith's Avatar
    Join Date
    Feb 2012
    Location
    Near you
    Posts
    116

    Re: Remembering Settings

    Sorry I don't have my computer with me so I can't check right now.
    "When ideas and actions fuse, they form creations"

  7. #7
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    9,017

    Re: Remembering Settings

    Quote Originally Posted by Brinith View Post
    I see, but to start it up, should it be like this?

    Name= My.Settings.Username
    Label1.Text = Name

    Sorry I am pretty much a complete beginner at programmer so Im probably way off.
    Yep.....or make it simpler:-
    vbnet Code:
    1. Label1.Text = My.Settings.Username
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena

    Copy/move files using Windows Shell | I'm not wanted

    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. - jmcilhinney

    The threads I start are Niya and Olaf free zones. No arguing about the benefits of VB6 over .NET here please. Happiness must reign. - yereverluvinuncleber

  8. #8

    Thread Starter
    Lively Member Brinith's Avatar
    Join Date
    Feb 2012
    Location
    Near you
    Posts
    116

    Re: Remembering Settings

    I see thanks for all your help guys
    "When ideas and actions fuse, they form creations"

  9. #9

    Thread Starter
    Lively Member Brinith's Avatar
    Join Date
    Feb 2012
    Location
    Near you
    Posts
    116

    Re: Remembering Settings

    Quote Originally Posted by jmcilhinney View Post
    Open the Settings page of the project properties and add a setting of the appropriate type with the appropriate name. You can then access that setting in code via the so-named property of My.Settings. Settings are automatically saved to the user config file at shutdown and loaded at startup. These settings are user-specific, so if you log into Windows as a different user then your app will have a different set of settings.
    Well it's for a school project so I don't think that should be a problem.
    "When ideas and actions fuse, they form creations"

Tags for this Thread

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