Click here to Skip to main content
15,905,682 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello, and I'm making a program that changes the value of some registry keys and the value needs to be exclusively Decimal format. How would I go about doing this?

VB
Shared Sub SetColorizationColor(ByVal color As String)
    Dim regKey As RegistryKey
    regKey = My.Computer.Registry.CurrentUser.OpenSubKey("Software\Microsoft\Windows\DWM", True)
    regKey.SetValue("AccentColor", 268435455)
    regKey.SetValue("ColorizationColor", Convert.ToDecimal(color))
    regKey.Close()
End Sub


The argument "color" in this instance is the textbox input. The function is taking the textbox input (a string) and converts it to a decimal and sets a registry key value to the returned decimal.

This spits out an exception upon being called, saying:
Quote:
Input string was not in a correct format.


What I have tried:

I've tried using the Decimal.Parse() method. No luck at all. I've tried seeing if the key takes another format, and it hasn't worked either.

Thank you for the help in advance!
Posted
Updated 26-Apr-19 13:15pm

1 solution

Decimal.TryParse will try to parse it. The issue is what the error says. You have not typed in a decimal. It can't parse a bad value
 
Share this answer
 
Comments
! E M O T I O N A L ! 26-Apr-19 19:21pm    
How would you suggest converting a string to a decimal?
Christian Graus 26-Apr-19 19:24pm    
Make sure the string is a decimal first
! E M O T I O N A L ! 26-Apr-19 19:26pm    
The string in the textbox is a HEX value. Excluding the hashtag of course.

I'll try do a color picker and convert that value to a decimal instead of a textbox.
Christian Graus 26-Apr-19 19:28pm    
Then it's not a decimal, is it?

Dim i As Integer = Convert.ToInt32("c001", 16)
! E M O T I O N A L ! 26-Apr-19 19:41pm    
I tried this suggestion and it always comes out as one single value no matter what value I put in the textbox. I've checked the registry values and they're the same no matter what as well.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900