将文本框字符串转换为双 VB.NET

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22405747/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-17 17:04:49  来源:igfitidea点击:

Convert Textbox string to Double VB.NET

vb.nettryparse

提问by GAltelino

i'm getting a problem everytime I try to convert an textbox value to a double, the value in the textbox will be used in a calculation with another double, and it's entried from keyboard, everytime i tried to run it I used just numbers on the textbox.

每次我尝试将文本框值转换为双精度值时都会遇到问题,文本框中的值将用于与另一个双精度值的计算,并且它是从键盘输入的,每次我尝试运行它时我只使用数字文本框。

    dim temporaryProduct as string
    Dim value, convertValue, finalValue As Double

temporaryProduct = mathForm.valueBox.tostring ' I've tried with .text too

            If Double.TryParse(temporaryProduct, value) Then 'Convert to double
                convertValue = value
            Else
                MsgBox("Tryparse error")
                Exit Sub
            End If

Everytime i try to convert the textbox string i get "Tryparse error", i really don't know what i'm doing wrong, and i need it to be in double.

每次我尝试转换文本框字符串时,我都会收到“Tryparse 错误”,我真的不知道自己做错了什么,我需要将它变成双份。

采纳答案by LarsTech

Try using just the Text property:

尝试仅使用 Text 属性:

temporaryProduct = mathForm.valueBox.Text

If you use the ToString function on a TextBox, you get something like this:

如果在 TextBox 上使用 ToString 函数,则会得到如下结果:

System.Windows.Forms.TextBox, Text: ???

System.Windows.Forms.TextBox,文本:???

which is obviously not a value you can use.

这显然不是您可以使用的值。