Settings Help

If you need help with a project or need to know how to do something specific in VB.NET then please ask your questions in here.
Forum rules
Please LOCK your topics once you have found the solution to your question so we know you no longer require help with your query.
15 posts Page 1 of 2
Contributors
User avatar
Cheatmasterbw
Coding God
Coding God
Posts: 1506
Joined: Fri Jan 01, 2010 2:30 pm

Settings Help
Cheatmasterbw
If i have CheckBox1 to 4 on a form, how would i make it so when i close the form and then open the program again the check state of all the checkboxes are the same as when they were when the form closed.

I would like to know how to make this without making a file (that includes temp files)

thanks!
http://www.megaapps.tk/
GoodGuy17
Coding God
Coding God
Posts: 1610
Joined: Mon Sep 07, 2009 12:25 am

Re: Settings Help
GoodGuy17
Add 4 settings.
CHK1 - Boolean - True
CHK2 - Boolean - False
CHK3 - Boolean - False
CHK4 - Boolean - False

Under Form_FormClosing, put:
If Checkbox1.checked = true then
my.settings.chk1 = true
elseif checkbox2.checked = true then
my.settings.chk2 = true
elseif...
etc
and under Form Load
If my.settings.chk1 = true then
checkbox1.checked = true
etc.
+rep if I helped! :D
User avatar
zachman61
VIP - Donator
VIP - Donator
Posts: 1892
Joined: Wed Dec 16, 2009 9:56 pm

Re: Settings Help
zachman61
he said making temp files this doesnt save for ever.
Nailing my feet to the floor is easier than using my own muscles to balance, but you don't see me doing that :)
User avatar
Cheatmasterbw
Coding God
Coding God
Posts: 1506
Joined: Fri Jan 01, 2010 2:30 pm

Re: Settings Help
Cheatmasterbw
I actually did not want temp files. Thanks Reboh, +1 Rep for you!

EDIT: When making a setting, What would the scope be in this situation? "User", "Application", or does it not matter? Thanks!
http://www.megaapps.tk/
User avatar
Usman55
VIP - Site Partner
VIP - Site Partner
Posts: 2821
Joined: Thu Dec 24, 2009 7:52 pm

Re: Settings Help
Usman55
Really helpful, Reboh. I'll be using this in my next application, which will be a Text To Speech application.
Image
User avatar
Cheatmasterbw
Coding God
Coding God
Posts: 1506
Joined: Fri Jan 01, 2010 2:30 pm

Re: Settings Help
Cheatmasterbw
I figured it out! Application is read only, and User is not!
http://www.megaapps.tk/
GoodGuy17
Coding God
Coding God
Posts: 1610
Joined: Mon Sep 07, 2009 12:25 am

Re: Settings Help
GoodGuy17
Last time I tested settings, it kept them when I moved the program to a different directory and stuff. The settings stayed the same at all times. Thanks Cheatmaster and Usman!
User avatar
Usman55
VIP - Site Partner
VIP - Site Partner
Posts: 2821
Joined: Thu Dec 24, 2009 7:52 pm

Re: Settings Help
Usman55
I want to do it with textbox, how to save its text so that next time the form loads, its text is same.
Image
User avatar
Agust1337
Coding God
Coding God
Posts: 2456
Joined: Fri Feb 19, 2010 8:18 pm

Re: Settings Help
Agust1337
Hello Usman55,
it's simple, you'll just have to create a settings and put it to string(And string is the default) And no value.
Have a button saying "Save" (There is no need for a button, you can save it on formclosing but I prefer with both)
Code: Select all
Private Sub txtSettingsName_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtSettingsName.TextChanged
        If txtSettingsName.Text = "" Then
            btnSave.Enabled = False
        Else
            btnSave.Enabled = True
        End If
    End Sub

    Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
        My.Settings.test = txtSettingsName.Text
        My.Settings.Save()
        My.Settings.Reload()
    End Sub

    Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        My.Settings.test = txtSettingsName.Text
        My.Settings.Save()
        My.Settings.Reload()
    End Sub

    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        txtSettingsName.Text = My.Settings.test
    End Sub
Top-notch casual Dating
User avatar
Usman55
VIP - Site Partner
VIP - Site Partner
Posts: 2821
Joined: Thu Dec 24, 2009 7:52 pm

Re: Settings Help
Usman55
Thanks Agust, I wanted this piece of code badly, thanks. And can you help me with a simple thing? I want my application if the directory which is written in a textbox exists then it's okay but if it doesn't exists than it should create one. It should be a text file though. I tried some code but it made a folder named Log.txt instead of a file.
Image
15 posts Page 1 of 2
Return to “Coding Help & Support”