473,385 Members | 1,813 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Registry SetValue stores double as REG_SZ

using Microsoft.Win32;
RegistryKey key = Registry.LocalMachine;
key = key.OpenSubKey(".....");
...
key = key.OpenSubKey("PCF", true);
double aDoubleValue = 0.25;
key.SetValue("testkey", aDoubleValue);

testkey pre-existed as a DWORD value and after the setvalue becomes a
REG_SZ type. Even tried casting the aDoubleValue, but no change.

Whats wrong with SetValue?

Thanks in advance.
Chuck

Jul 30 '05 #1
1 5699
Hello Chuck,
testkey pre-existed as a DWORD value and after the setvalue becomes a
REG_SZ type. Even tried casting the aDoubleValue, but no change.


The native types for registry values are strings, binary values and DWORDs
(integers). There is no native type for storing a floating point value. If
you give the SetValue method a double value, it gets converted to a string.
So, the method works as expected.

You should either round or convert the value to an Int32 first, or store it
as a binary value if a string won't do. For example:

--------------------------------
Microsoft.Win32.RegistryKey key =
Registry.CurrentUser.OpenSubKey("Software\\ACME",t rue);
double myValue = 123.45;
key.SetValue("My Value",System.Convert.ToInt32(myValue));
key.Close();

--------------------------------

Hope this helps.

--
Regards,

Mr. Jani Järvinen
C# MVP
Helsinki, Finland
ja***@removethis.dystopia.fi
http://www.saunalahti.fi/janij/
Jul 31 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Yogi_Bear_79 | last post by:
I'm Creating new Keys in the registry, but when I do, they always have a Vaule called (Default) type RG_SZ. I need them to be DWord dword:00000005 Is there a way to automaticaly make the...
2
by: Ty Moffett | last post by:
Below is a set of insructions that changes the registry keys pertaining to Automatic Updates on my Windows XP box. I can make changes using the control panel applet and see the changes reflected...
6
by: CMG | last post by:
I am writing a little code to associate an extention with my program. And as far as i can see, i need to do the following: Public Function associatefile(ByVal FILE_EXTENTION_TO_ASSOCIATE As...
3
by: David Gacek | last post by:
How do you write a new Reg_Expand_sz value to the resgistry with vb.net this used to work when you pad the string with a null. Anyone know how or what i'm doing wrong ? It just writes a new...
5
by: Dave | last post by:
I'd like to create a Registry key value where the Registry key value type is REG_QWORD. I'm using SetValue(name As String, value As Object), and I understand that the object type used in this...
3
by: Joe Delphi | last post by:
Hi, I want to store non-string values in the registry. I have a few Boolean flags and some integer numbers that I want to store. It appears that the SaveSettings command only handles the...
1
by: ChuckD_Duncan | last post by:
using Microsoft.Win32; RegistryKey key = Registry.LocalMachine; key = key.OpenSubKey("....."); ... key = key.OpenSubKey("PCF", true); double aDoubleValue = 0.25; key.SetValue("testkey",...
3
by: Aussie Rules | last post by:
Hi, I want to store some data in the registry, however I have not been able to do this, and think my logic maybe flawed. Firstly I try to open the registry and read in any existing values....
9
by: Newbie Coder | last post by:
Hello Newsgroup Readers I would like to know how to go & do the following: I have a certain registry key that has sub values Example: Key1 http://www.microsoft.com Key2 ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.