无法在Label Box中显示计算值-Visual Basic

时间:2019-05-18 18:35:47

标签: vb.net label double

编码新手,一切似乎都正确,但是当我按计算时,

财产税显示:“税款为$ 000.00”,而不是实际的计算值。

Private Sub btnExit_Click(sender As Object, e As EventArgs) Handles btnExit.Click
    Me.Close()
End Sub

Private Sub btnCalculate_Click(sender As Object, e As EventArgs) Handles btnCalculate.Click
    Dim txtValue As Double 'Declare variable To hold the Property value'
    Dim lblTax As Double 'to calculate the tax value'
    If Not Double.TryParse(txtValue, lblTax) Then 'check for the enter number
    Else
        lblTax = (txtValue * 0.0135) 'calculate the 1.35% of property value
        'format the results as a $ currency.
        lblTaxSolution.Text = "Tax is: " & lblTax.ToString("$0,00.00") 'display the number with formatted output
    End If
End Sub

enter image description here

1 个答案:

答案 0 :(得分:0)

将文本框重命名为“ txtValue”(无需创建单独的变量)。使用以下代码片段,您将获得预期的结果。

Dim lblTax As Double 'to calculate the tax value'
        If Not Double.TryParse(txtValue.text, lblTax) Then 'check for the enter number
        Else
            lblTax = (txtValue.Text * 0.0135) 'calculate the 1.35% of property value
            'format the results as a $ currency.
            lblTaxSolution.Text = $"Tax is: {lblTax:$0,00.00}" 'display the number with formatted output
        End If