Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vb.net 未处理格式异常_Vb.net_Visual Studio 2010 - Fatal编程技术网

Vb.net 未处理格式异常

Vb.net 未处理格式异常,vb.net,visual-studio-2010,Vb.net,Visual Studio 2010,material=Decimal.Parse(AmountTextBox.Text)将不运行。 为什么?文本框中的字符串值是多少 将返回一个错误,而不是抛出。试试看。我认为GregC的意思是,您需要使用如下代码: Dim labor, material, partstotal, labortotal, subtotal, tax, total As Decimal material = Decimal.Parse(AmountTextBox.Text) labor = D

material=Decimal.Parse(AmountTextBox.Text)将不运行。
为什么?

文本框中的字符串值是多少


将返回一个错误,而不是抛出。试试看。

我认为GregC的意思是,您需要使用如下代码:

    Dim labor, material, partstotal, labortotal, subtotal, tax, total As Decimal
    material = Decimal.Parse(AmountTextBox.Text)
    labor = Decimal.Parse(LaborTextBox.Text)

    partstotal = material
    labortotal = labor * 50
    subtotal = labortotal + partstotal
    tax = subtotal * 0.08
    total = subtotal + tax

    partstotal = Decimal.Parse(PartsTextBox.Text)
    labortotal = Decimal.Parse(LaborTextBox.Text)
    subtotal = Decimal.Parse(SubTotalTextBox.Text)
    tax = Decimal.Parse(SalesTaxTextBox.Text)
    total = Decimal.Parse(TotalTextBox.Text)

尽管有那么多的项目需要验证,但您可能可以通过使用提供更好的用户体验。

我不确定您在问什么,而且labor=Decimal.Parse(LaborTextBox.Text)不会运行either@ScottESwingle应该可以在调试器中捕获文本字段的值,或者简单地从表单复制粘贴它们。由于无法分析用户输入,可能会发生异常。您所说的“不运行”是什么意思?它似乎抛出了一个异常,对吗?在此处复制和粘贴错误将有助于获得正确答案;)
Dim material As Decimal
If Not Decimal.TryParse(AmountTextBox.Text, material) Then
    ' the text in AmountTextBox could not be parsed as
    ' a Decimal.
    'TODO: do something about it.
End If