|
-
Oct 9th, 2006, 03:44 PM
#1
Thread Starter
Lively Member
[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:
Dim key As Microsoft.Win32.RegistryKey
key = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("SOFTWARE\Microsoft\Windows\CurrentVersion\Run", True)
If CheckBox3.Checked = True Then
key.SetValue("Notes", Application.ExecutablePath)
MsgBox("Set '" & CType(key.GetValue("Notes"), String) & "' to open at system startup.")
Else
key.DeleteValue("Notes")
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.
-
Oct 9th, 2006, 03:59 PM
#2
Banned
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 ?
-
Oct 9th, 2006, 04:19 PM
#3
Thread Starter
Lively Member
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.
-
Oct 10th, 2006, 12:18 AM
#4
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.
-
Oct 10th, 2006, 02:38 PM
#5
Thread Starter
Lively Member
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?
-
Oct 10th, 2006, 05:35 PM
#6
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).
-
Oct 11th, 2006, 05:39 PM
#7
Thread Starter
Lively Member
Re: [2005] open at startup+checkbox
here's what i have:
VB Code:
Private Sub CheckBox3_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox3.CheckedChanged
SaveSetting("Notes", "Save", "Open Startup", CheckBox3.Checked)
End Sub
VB Code:
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
CheckBox3.Checked = GetSetting("Notes", "Save", "Open Startup", "False")
End Sub
It doesn't save the value of the checkbox... it just puts the default one
-
Oct 11th, 2006, 06:00 PM
#8
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.
-
Oct 11th, 2006, 07:16 PM
#9
Thread Starter
Lively Member
Re: [2005] open at startup+checkbox
oh ic what you mean... but how would i make it do so?
-
Oct 11th, 2006, 07:19 PM
#10
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.
-
Oct 13th, 2006, 01:32 PM
#11
Thread Starter
Lively Member
Re: [2005] open at startup+checkbox
ok i completely understand what you mean, but how to compare it?
-
Oct 13th, 2006, 01:42 PM
#12
Re: [2005] open at startup+checkbox
here an example
VB Code:
Dim key As Microsoft.Win32.RegistryKey
key = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("SOFTWARE\Microsoft\Windows\CurrentVersion\Run", True)
If key.GetValue("Notes", Nothing) IsNot Nothing Then
MessageBox.Show("The key exist")
Else
MessageBox.Show("The key does not exist")
End If
Last edited by VBDT; Oct 13th, 2006 at 02:06 PM.
-
Oct 16th, 2006, 03:56 PM
#13
Thread Starter
Lively Member
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
-
Oct 16th, 2006, 05:07 PM
#14
Re: [2005] open at startup+checkbox
if you have exacly the same way i showed you it shouldn't be underlined. Post that part.
-
Oct 16th, 2006, 05:43 PM
#15
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:rather than:If you're using 2005 as your post says then it will work exactly as VBDT has suggested, exactly as VBDT says.
-
Oct 16th, 2006, 06:31 PM
#16
Re: [2005] open at startup+checkbox
-
Oct 16th, 2006, 06:41 PM
#17
Re: [2005] open at startup+checkbox
 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.
-
Oct 16th, 2006, 06:48 PM
#18
Re: [2005] open at startup+checkbox
I know! I am just playing with you. This is what happens when one gets bored.
-
Oct 17th, 2006, 01:43 PM
#19
Thread Starter
Lively Member
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
-
Oct 17th, 2006, 01:58 PM
#20
Frenzied Member
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.
-
Oct 17th, 2006, 07:12 PM
#21
Thread Starter
Lively Member
Re: [2005] open at startup+checkbox
-
Oct 17th, 2006, 07:24 PM
#22
Frenzied Member
Re: [2005] open at startup+checkbox
Then you need to use example 2 in post 15.
-
Oct 17th, 2006, 08:28 PM
#23
Re: [2005] open at startup+checkbox
 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.
-
Oct 17th, 2006, 08:30 PM
#24
Frenzied Member
Re: [2005] open at startup+checkbox
oops. Sorry about that. That's what I meant. Memory of a goldfish.
-
Oct 18th, 2006, 06:07 PM
#25
Thread Starter
Lively Member
Re: [2005] open at startup+checkbox
oh sweet thanks then it works
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
|