如何在VB.NET中将文本框输入转换为十进制? [英] How to convert textbox input to decimal in VB.NET?

查看:106
本文介绍了如何在VB.NET中将文本框输入转换为十进制?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我正在制作一个程序来更改某些注册表项的值,并且该值必须是专门的十进制格式。我该怎么做呢?



 共享  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( < span class =code-string> ColorizationColor,Convert.ToDecimal(color))
regKey.Close()
End Sub





此实例中的参数color是文本框输入。该函数正在获取文本框输入(字符串)并将其转换为小数并将注册表项值设置为返回的小数。



这会吐出异常被叫,说:

Quote:

输入字符串的格式不正确。





我尝试了什么:



我尝试过使用Decimal.Parse()方法。没有运气。我试过看看密钥是否采用了另一种格式,而且它也没有用。



提前感谢您的帮助!

解决方案

Decimal.TryParse将尝试解析它。问题出在错误上。您没有输入小数。它无法解析错误值

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?

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!

解决方案

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


这篇关于如何在VB.NET中将文本框输入转换为十进制?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆