|
-
Oct 18th, 2006, 07:10 PM
#1
Thread Starter
Lively Member
[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?
Last edited by smart_phil_dude1; Nov 3rd, 2006 at 04:29 PM.
Reason: Problem Solved
-
Oct 18th, 2006, 07:32 PM
#2
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.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Oct 19th, 2006, 12:45 PM
#3
Thread Starter
Lively Member
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...
-
Oct 19th, 2006, 01:09 PM
#4
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
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Oct 22nd, 2006, 04:21 PM
#5
Thread Starter
Lively Member
Re: [02/03] Problem w/ Code
good thinking, but i already tried that and it didn't work
-
Oct 22nd, 2006, 04:42 PM
#6
Hyperactive Member
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
-
Oct 27th, 2006, 02:20 PM
#7
Thread Starter
Lively Member
Re: [02/03] Problem w/ Code
i know that, but it just changes it back no matter what!
-
Oct 27th, 2006, 05:46 PM
#8
Re: [02/03] Problem w/ Code
Upload your project and we can help debug it.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Oct 30th, 2006, 04:04 PM
#9
Thread Starter
Lively Member
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
but i already gave all of the code that i put in that effects this.
-
Oct 30th, 2006, 04:12 PM
#10
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".
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Nov 2nd, 2006, 09:06 PM
#11
Thread Starter
Lively Member
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
Last edited by smart_phil_dude1; Nov 3rd, 2006 at 04:27 PM.
-
Nov 2nd, 2006, 09:27 PM
#12
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.
-
Nov 3rd, 2006, 04:28 PM
#13
Thread Starter
Lively Member
Re: [02/03] Problem w/ Code
holy crap thanks a lot this is really helpful. reps for you
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|