Results 1 to 8 of 8

Thread: Help with my sticky notes program

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2007
    Posts
    9

    Help with my sticky notes program

    OK well, as my very first VB program i am creating "sticky notes" little reminders that sit on your desktop with notes u can type in. (im sure you all know what im talking about).

    Anyways, i have most of the functionality down except but i have some problems:

    1. i am unaware of how the user can save their notes so next time it starts up it will load the most recent note they have wrote down.

    2. How to make the title bar not visible

    3. To give the user the option to have the program run on startup. I have most of the code down for this one but i get these errors

    (i spaced it so it is easier to read)

    Code:
    Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged
    
            If CheckBox1.Checked = True Then
    
                My.Computer.Registry.LocalMachine.OpenSubKey("SOFTWARE\Microsoft\Windows\CurrentVersion\Run", True)
    
                My.Computer.Registry.LocalMachine.SetValue("Sticky Notes", Application.ExecutablePath.ToString("C:\Users\derrek\Desktop\Sticky Notes.application") & " -min")
    
                My.Computer.Registry.LocalMachine.Close()
    
            Else : My.Computer.Registry.LocalMachine.DeleteValue("Sticky Notes", False)
    
            End If
    
        End Sub
    
    End Class
    ERRORS:

    A first chance exception of type 'System.NullReferenceException' occurred in Sticky Notes.exe

    A first chance exception of type 'System.InvalidCastException' occurred in Sticky Notes.exe

    A first chance exception of type 'System.InvalidCastException' occurred in Sticky Notes.exe


    if anyone wants to see the code so far just ask me to post it

    You help is greatly appreciated.

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

    Re: Help with my sticky notes program

    When the debugger tells you a first chance exception occurred, that just tells you that an exception was thrown. That in itself is not necessarily a bad thing. Exceptions are allowed to be thrown. If your app isn't crashing then those exceptions must be being caught, so there's not likely to be an issue. If the exceptions are being thrown in your own code then you should examine where and why, and fix any issue that may be avoidable. Otherwise it's happening in system code and is beyond your control anyway.

    As to your questions:

    1. You need to save the data to disk somehow. That might mean using a text file, a data file in a format of your own creation, a database or My.Settings. Which you choose is up to you.

    2. Set the BorderStyle of the form to None.

    3. This code is wrong:
    vb.net Code:
    1. My.Computer.Registry.LocalMachine.SetValue("Sticky Notes", Application.ExecutablePath.ToString("C:\Users\derrek\Desktop\Sticky Notes.application") & " -min")
    It should just be:
    vb.net Code:
    1. My.Computer.Registry.LocalMachine.SetValue("Sticky Notes", Application.ExecutablePath & " -min")
    That said, I'd be inclined to replace that whole snippet with this:
    vb.net Code:
    1. My.Computer.Registry.SetValue("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run", _
    2.                               Application.ProductName, _
    3.                               Application.ExecutablePath & " -min")
    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

  3. #3

    Thread Starter
    New Member
    Join Date
    Jan 2007
    Posts
    9

    Re: Help with my sticky notes program

    k thanks for that great reply, now it gets written into the reg, but when i uncheck the box, it doesnt get deleted from the registry =\

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

    Re: Help with my sticky notes program

    Look at this:
    vb.net Code:
    1. My.Computer.Registry.LocalMachine.DeleteValue("Sticky Notes", False)
    That's attempting to delete the value named "Sticky Notes" for the key with path "HKEY_LOCAL_MACHINE". Does that key have such a value? No it doesn't. You're setting the value at one key and then trying to delete it from another.
    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
    New Member
    Join Date
    Jan 2007
    Posts
    9

    Re: Help with my sticky notes program

    sorry for the stupid question but how would i point it in the direction of where the ket is located, i know where it is, but how would i implement that into the code?

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

    Re: Help with my sticky notes program

    You've already implemented it. Look at your original code and how you're setting the value in the first place. How do you suppose you'd adapt that to delete a value instead?
    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
    New Member
    Join Date
    Jan 2007
    Posts
    9

    Re: Help with my sticky notes program

    i tried this
    Code:
    If CheckBox1.Checked = False Then
                My.Computer.Registry.CurrentUser.DeleteSubKey("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run\WindowsApplication1", False)
            End If
    still didnt work.. and the reg key wasnt sticky notes =/

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

    Re: Help with my sticky notes program

    OK, I just had a closer look at your code and I realised another mistake you were making in your original code. You were opening the key "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run" but then you were trying to set a value of the key "HKEY_LOCAL_MACHINE". You never opened that key to write so the value would not be written. OpenSubKey returns a RegistryKey object. It is the SetValue method of THAT object you should have been calling.

    Now, I've fixed that by providing you with a one-liner to set a value on a specific key. The My.Computer.Registry object has no DeleteValue method though, so for that you do have to use three lines of code. They have to be the correct lines though. You have to open the correct key, delete the value from that key and no other, then close the key:
    vb.net Code:
    1. Dim key As RegistryKey = My.Computer.Registry.LoacalMachine.OpenSubKey(subKeyPath, True)
    2.  
    3. key.DeleteValue(valueName)
    4. key.Close()
    Now it's your turn. What are the appropriate subKeyPath and valueName, assuming that you're using my code from post #2 to set the value in the first place?
    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

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