473,324 Members | 2,456 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,324 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 5688
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: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.