Results 1 to 13 of 13

Thread: [Solved] [02/03] Problem w/ Code

  1. #1

    Thread Starter
    Lively Member smart_phil_dude1's Avatar
    Join Date
    Jun 2005
    Location
    Behind You!
    Posts
    125

    Resolved [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:
    1. Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged
    2.         SaveSetting("Notes", "Save", "Save Text", CheckBox1.Checked)
    3.     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:
    1. Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
    2.         If GetSetting("Notes", "Save", "Save Text") = True Then
    3.             CheckBox1.Checked = True
    4.         Else
    5.             CheckBox1.Checked = False
    6.         End If
    7.     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
    Please Help Us Save Ana or donate now by going to Oneana.com

    Visit my Website at http://www.therealfantasy.com

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    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 PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI 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

  3. #3

    Thread Starter
    Lively Member smart_phil_dude1's Avatar
    Join Date
    Jun 2005
    Location
    Behind You!
    Posts
    125

    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...
    Please Help Us Save Ana or donate now by going to Oneana.com

    Visit my Website at http://www.therealfantasy.com

  4. #4
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    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 PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI 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

  5. #5

    Thread Starter
    Lively Member smart_phil_dude1's Avatar
    Join Date
    Jun 2005
    Location
    Behind You!
    Posts
    125

    Re: [02/03] Problem w/ Code

    good thinking, but i already tried that and it didn't work
    Please Help Us Save Ana or donate now by going to Oneana.com

    Visit my Website at http://www.therealfantasy.com

  6. #6
    Hyperactive Member josep's Avatar
    Join Date
    Sep 2006
    Location
    Barcelona
    Posts
    409

    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
    Useful links:DB connection strings ADO.NET VB.NET Tutorials

    • Don't forget to close the thread if solved
    • If this post helps you rate it

  7. #7

    Thread Starter
    Lively Member smart_phil_dude1's Avatar
    Join Date
    Jun 2005
    Location
    Behind You!
    Posts
    125

    Re: [02/03] Problem w/ Code

    i know that, but it just changes it back no matter what!
    Please Help Us Save Ana or donate now by going to Oneana.com

    Visit my Website at http://www.therealfantasy.com

  8. #8
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    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 PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI 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

  9. #9

    Thread Starter
    Lively Member smart_phil_dude1's Avatar
    Join Date
    Jun 2005
    Location
    Behind You!
    Posts
    125

    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.
    Please Help Us Save Ana or donate now by going to Oneana.com

    Visit my Website at http://www.therealfantasy.com

  10. #10
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    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 PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI 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

  11. #11

    Thread Starter
    Lively Member smart_phil_dude1's Avatar
    Join Date
    Jun 2005
    Location
    Behind You!
    Posts
    125

    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.
    Please Help Us Save Ana or donate now by going to Oneana.com

    Visit my Website at http://www.therealfantasy.com

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

    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:
    1. Private Const APP_NAME As String = "AppName"
    2. Private Const SECTION As String = "Section"
    3. Private Const KEY As String = "Key"
    4.  
    5. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    6.     'Check the CheckBox if the setting doesn't contain some form of "false".
    7.     Me.CheckBox1.Checked = (GetSetting(APP_NAME, _
    8.                                        SECTION, _
    9.                                        KEY, _
    10.                                        True.ToString()).ToLower() <> "false")
    11. End Sub
    12.  
    13. Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged
    14.     SaveSetting(APP_NAME, _
    15.                 SECTION, _
    16.                 KEY, _
    17.                 Me.CheckBox1.Checked.ToString())
    18. End Sub
    Note that a simple breakpoint in the CheckChanged event handler would have brought this issue to light.
    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

  13. #13

    Thread Starter
    Lively Member smart_phil_dude1's Avatar
    Join Date
    Jun 2005
    Location
    Behind You!
    Posts
    125

    Re: [02/03] Problem w/ Code

    holy crap thanks a lot this is really helpful. reps for you
    Please Help Us Save Ana or donate now by going to Oneana.com

    Visit my Website at http://www.therealfantasy.com

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