Page 1 of 2

Settings Help

Posted: Fri Nov 26, 2010 7:09 pm
by 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!

Re: Settings Help

Posted: Fri Nov 26, 2010 7:24 pm
by 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

Re: Settings Help

Posted: Fri Nov 26, 2010 7:40 pm
by zachman61
he said making temp files this doesnt save for ever.

Re: Settings Help

Posted: Fri Nov 26, 2010 7:44 pm
by 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!

Re: Settings Help

Posted: Sat Nov 27, 2010 1:52 am
by Usman55
Really helpful, Reboh. I'll be using this in my next application, which will be a Text To Speech application.

Re: Settings Help

Posted: Sat Nov 27, 2010 2:07 am
by Cheatmasterbw
I figured it out! Application is read only, and User is not!

Re: Settings Help

Posted: Sun Nov 28, 2010 2:47 am
by 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!

Re: Settings Help

Posted: Wed Dec 01, 2010 5:46 pm
by Usman55
I want to do it with textbox, how to save its text so that next time the form loads, its text is same.

Re: Settings Help

Posted: Fri Dec 10, 2010 12:55 pm
by 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

Re: Settings Help

Posted: Fri Dec 10, 2010 2:23 pm
by 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.