Results 1 to 25 of 25

Thread: [2005] open at startup+checkbox

  1. #1

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

    Resolved [2005] open at startup+checkbox

    kk i have the following code to have a checkbox to have the program automatically open at startup or not:
    VB Code:
    1. Dim key As Microsoft.Win32.RegistryKey
    2.         key = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("SOFTWARE\Microsoft\Windows\CurrentVersion\Run", True)
    3.  
    4.         If CheckBox3.Checked = True Then
    5.             key.SetValue("Notes", Application.ExecutablePath)
    6.             MsgBox("Set '" & CType(key.GetValue("Notes"), String) & "' to open at system startup.")
    7.         Else
    8.             key.DeleteValue("Notes")
    9.         End If

    well it works perfectly fine but i noticed a little problem... when re-loading the application, i noticed that the checkbox is set back to the default setting (unchecked)

    i want the app to check, as soon as the form is loaded, to see if the app is already in the registry to run at startup, and if so then have the checkbox checked, but if not then have it unchecked


    all help would be appreciated
    thanks
    cheers,
    Phil.
    Last edited by smart_phil_dude1; Oct 18th, 2006 at 06:07 PM.
    Please Help Us Save Ana or donate now by going to Oneana.com

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

  2. #2
    Banned
    Join Date
    May 2006
    Posts
    161

    Re: [2005] open at startup+checkbox

    Well of course it is going to do that...how will the form remember the checked value if it is reloaded? You will need to read back into the form the original value you intend.
    Makes sense no ?

  3. #3

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

    Re: [2005] open at startup+checkbox

    i don't get what your going at...

    can i get some bits of code please?
    Last edited by smart_phil_dude1; Oct 9th, 2006 at 07:02 PM.
    Please Help Us Save Ana or donate now by going to Oneana.com

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

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

    Re: [2005] open at startup+checkbox

    Think about it. Every time you start the application the CheckBox is going to be whatever you set it to at design time. If you want it to reflect the setting in the registry then you have to tell it so. You have to check the registry to see if that value is there and set the state of the CheckBox accordingly. That's what JAKSupport is saying.

    Alternatively you could bind the CheckBox to an application setting but I'd probably recommend against that because then it is conceivable, if unlikely, that the two could get out of sync.
    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

  5. #5

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

    Re: [2005] open at startup+checkbox

    yeah well that's what i was trying to do, how can i make it check to see if the value exists?
    Please Help Us Save Ana or donate now by going to Oneana.com

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

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

    Re: [2005] open at startup+checkbox

    The RegistryKey.GetValue method will return the actual value if a registry value with the specifed name exists or Nothing if it doesn't. You simply have to set the Checked property of your CheckBox to (GetValue IsNot Nothing).
    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

  7. #7

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

    Re: [2005] open at startup+checkbox

    here's what i have:

    VB Code:
    1. Private Sub CheckBox3_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox3.CheckedChanged
    2.         SaveSetting("Notes", "Save", "Open Startup", CheckBox3.Checked)
    3.     End Sub

    VB Code:
    1. Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
    2.         CheckBox3.Checked = GetSetting("Notes", "Save", "Open Startup", "False")
    3.     End Sub

    It doesn't save the value of the checkbox... it just puts the default one
    Please Help Us Save Ana or donate now by going to Oneana.com

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

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

    Re: [2005] open at startup+checkbox

    Noone said anything about using SaveSetting or GetSetting. They have absolutely nothing to do with the Run registry key so they are no help whatsoever in this situation. Let me start again.

    When you shutdown your app you will be testing whether the check box is checked, correct?

    If it is checked then you open the Run key and use SetValue to place a value for your app in the regsitry, correct?

    If it is not checked then you have to Open the Run key and call DeleteValue to remove the value for your application, correct?

    Now, when you start your app you have to open the Run key and call GetValue to see if there is a value there for your app. If GetValue returns a value then you need to check your check box. If GetValue returns Nothing then there is no value there so you don't check the check box.
    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

  9. #9

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

    Re: [2005] open at startup+checkbox

    oh ic what you mean... but how would i make it do so?
    Please Help Us Save Ana or donate now by going to Oneana.com

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

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

    Re: [2005] open at startup+checkbox

    In your very first post you've used GetValue so you already know how to use it. All you have to do is compare its return value to Nothing. That will give you True or False. The Checked property of a CheckBox requires a True or False value.
    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

  11. #11

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

    Re: [2005] open at startup+checkbox

    ok i completely understand what you mean, but how to compare it?
    Please Help Us Save Ana or donate now by going to Oneana.com

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

  12. #12
    PowerPoster VBDT's Avatar
    Join Date
    Sep 2005
    Location
    CA - USA
    Posts
    2,922

    Re: [2005] open at startup+checkbox

    here an example
    VB Code:
    1. Dim key As Microsoft.Win32.RegistryKey
    2.         key = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("SOFTWARE\Microsoft\Windows\CurrentVersion\Run", True)
    3.  
    4.         If key.GetValue("Notes", Nothing) IsNot Nothing Then
    5.             MessageBox.Show("The key exist")
    6.         Else
    7.             MessageBox.Show("The key does not exist")
    8.         End If

  13. #13

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

    Re: [2005] open at startup+checkbox

    kk thanks a lot it was the nothing part i was looking for..


    except that the "IsNot Nothing Then" part is underlined blue and says end of statement expected
    Please Help Us Save Ana or donate now by going to Oneana.com

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

  14. #14
    PowerPoster VBDT's Avatar
    Join Date
    Sep 2005
    Location
    CA - USA
    Posts
    2,922

    Re: [2005] open at startup+checkbox

    if you have exacly the same way i showed you it shouldn't be underlined. Post that part.

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

    Re: [2005] open at startup+checkbox

    The 'IsNot' keyword is new in VB 2005. If you're using 2005 then it's valid. Are you actually using an earlier? If so then you need to use:
    VB Code:
    1. If Not X Is Y Then
    rather than:
    VB Code:
    1. If X IsNot Y Then
    If you're using 2005 as your post says then it will work exactly as VBDT has suggested, exactly as VBDT says.
    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

  16. #16
    PowerPoster VBDT's Avatar
    Join Date
    Sep 2005
    Location
    CA - USA
    Posts
    2,922

    Re: [2005] open at startup+checkbox

    If you're using 2005 as your post says then it will work exactly as VBDT has suggested, exactly as VBDT says.
    Are you trying to make a fun of me? No, I am not serious! Thanks for correcting me; I actually learned a lot from you. English is not my native language and I am too lazy to check my spelling so there it goes.

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

    Re: [2005] open at startup+checkbox

    Quote Originally Posted by VBDT
    Are you trying to make a fun of me? No, I am not serious! Thanks for correcting me; I actually learned a lot from you. English is not my native language and I am too lazy to check my spelling so there it goes.
    You suggested a way to make it work. You said that it would work exactly as you had suggested. I'm saying that, exactly as you said, it will work exactly as you had suggested. If I was making fun you'd know.
    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

  18. #18
    PowerPoster VBDT's Avatar
    Join Date
    Sep 2005
    Location
    CA - USA
    Posts
    2,922

    Re: [2005] open at startup+checkbox

    I know! I am just playing with you. This is what happens when one gets bored.

  19. #19

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

    Re: [2005] open at startup+checkbox

    well, thanks but i have the .NET version... isn't .NET and 2005 the same version?

    it's still underlined
    Please Help Us Save Ana or donate now by going to Oneana.com

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

  20. #20
    Frenzied Member
    Join Date
    Jul 2005
    Posts
    1,521

    Re: [2005] open at startup+checkbox

    .Net and 2005 are not the same thing. There are 3 different versions of .Net out there

    .Net 1.0 2002
    .Net 1.1 2003
    .Net 2.0 2005

    You can determine what version you are using by going to Help -> About. It will tell you there.
    Visual Studio Team Edition 2005
    GDI+ Links: Bob Powell VB.Net Heaven
    API Links: All API Pinvoke.Net
    VB6 to VB.Net: Visual Basic 6 to .NET Function Equivalents (Thread)

  21. #21

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

    Re: [2005] open at startup+checkbox

    oh ic, it's 2003
    Please Help Us Save Ana or donate now by going to Oneana.com

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

  22. #22
    Frenzied Member
    Join Date
    Jul 2005
    Posts
    1,521

    Re: [2005] open at startup+checkbox

    Then you need to use example 2 in post 15.
    Visual Studio Team Edition 2005
    GDI+ Links: Bob Powell VB.Net Heaven
    API Links: All API Pinvoke.Net
    VB6 to VB.Net: Visual Basic 6 to .NET Function Equivalents (Thread)

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

    Re: [2005] open at startup+checkbox

    Quote Originally Posted by mpdeglau
    Then you need to use example 2 in post 15.
    The first example is valid for .NET 1.x or .NET 2.0. The second example is valid for .NET 2.0 only.
    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

  24. #24
    Frenzied Member
    Join Date
    Jul 2005
    Posts
    1,521

    Re: [2005] open at startup+checkbox

    oops. Sorry about that. That's what I meant. Memory of a goldfish.
    Visual Studio Team Edition 2005
    GDI+ Links: Bob Powell VB.Net Heaven
    API Links: All API Pinvoke.Net
    VB6 to VB.Net: Visual Basic 6 to .NET Function Equivalents (Thread)

  25. #25

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

    Re: [2005] open at startup+checkbox

    oh sweet thanks then it works
    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