[Solved] [02/03] Problem w/ Code
kk, i have a richtextbox, and if checkbox1 is checked, then it saves the text from the richtextbox when some text is changed.
VB Code:
Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged
SaveSetting("Notes", "Save", "Save Text", CheckBox1.Checked)
End Sub
this is the code i used to save if the checkbox is checked or not. it works.
although, when i restart the app, the checkbox is the default one... so i used:
VB Code:
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
If GetSetting("Notes", "Save", "Save Text") = True Then
CheckBox1.Checked = True
Else
CheckBox1.Checked = False
End If
End Sub
although no matter what, it puts the checkbox back to checked when i open the app... even if the value actually is False, it just puts it to true
i even check with my regedit and saw that it saved it as false when i unchecked it. but when i restarted it, i rechecked the regedit and it was changed to true and the checkbox was checked....
what's my problem here?
Re: [02/03] Problem w/ Code
You should not be using the VB 6 SaveSetting and GetSetting functions. Using an xml file for your app settings is the new way to go. In the sticky thread at the top of the vb.net forums contains several project examples that all use the xml settings technique.
What does your Form_Closing or your terminating code look like where the checkbox settin is updated.
Re: [02/03] Problem w/ Code
i don't have anything for the form close, but i keeps it like it's supposed to be when i close it.
the save setting still works to save though, and i wrather not use xml...
Re: [02/03] Problem w/ Code
Ok, then lets look at what you have posted so far.
The CheckBox1.Checked value being saved to the registry is a value of "True" or "False" since the savesetting function only saves strings the boolean value is changed to string.
Your evaluation of this needs fixing too.
If GetSetting("Notes", "Save", "Save Text") = True Then
So your "Save Text" key will have a value of "True" or "False" and the If statement will eval it as "True" wich is not equal to True. ;)
Try...
If GetSetting("Notes", "Save", "Save Text") = "True" Then
Re: [02/03] Problem w/ Code
good thinking, but i already tried that and it didn't work
Re: [02/03] Problem w/ Code
Hi
Just set a breakpoint on the if condition and check for the value of
GetSetting("Notes", "Save", "Save Text")
The you will know the var type and the value of this variable
Re: [02/03] Problem w/ Code
i know that, but it just changes it back no matter what!
Re: [02/03] Problem w/ Code
Upload your project and we can help debug it.
Re: [02/03] Problem w/ Code
well, i don't really like uploading my stuff in case someone takes it and names it their own :eek2:
but i already gave all of the code that i put in that effects this.
Re: [02/03] Problem w/ Code
Without having your app to debug through it makes it really hard. Only thing is that you should be comparing apples to apples so you should be comparing the reg value being = to "True" or "False" and make sure its not "1" and "0".
Re: [02/03] Problem w/ Code
i tried out 1 and 0 and they both don't work...
i tried make a variable as boolean AND as string but they both didn't work...
here, i'll put my project here as an attachment then, trusting you guys.
it's a notepad type of thing
Re: [02/03] Problem w/ Code
What is the Checked property of your CheckBox set to in the designer? I'm guessing that it is True, thus when you create your form the Checked property is set to True, thus the CheckedChanged event is raised and True is saved to the registry. Then when the Load event handler executs it goes to the registry to get the value and it's True, no matter what was saved during the last session.
You need to make sure that the CheckBox is NOT checked in the designer. If you want the default state to be Checked then you should do this:
VB Code:
Private Const APP_NAME As String = "AppName"
Private Const SECTION As String = "Section"
Private Const KEY As String = "Key"
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Check the CheckBox if the setting doesn't contain some form of "false".
Me.CheckBox1.Checked = (GetSetting(APP_NAME, _
SECTION, _
KEY, _
True.ToString()).ToLower() <> "false")
End Sub
Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged
SaveSetting(APP_NAME, _
SECTION, _
KEY, _
Me.CheckBox1.Checked.ToString())
End Sub
Note that a simple breakpoint in the CheckChanged event handler would have brought this issue to light.
Re: [02/03] Problem w/ Code
holy crap thanks a lot this is really helpful. reps for you