我不断收到这条烦人的消息(即使这是我的错):
从字符串“”到类型“Double”的转换无效。
当我在 VB 2010 Express 中调试并点击“SLM”按钮时,我收到此消息。这到底是什么意思,我做错了什么?!?!
我的代码:
Public Class frmAssignment_5
Private Sub btnSLM_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSLM.Click
Dim Description As String
Dim Year As String
Dim Life As String
Dim SLMDepreciation As String
Dim SLMText As String = "straight-line"
txtDescription.Clear()
txtYear.Clear()
txtCost.Clear()
txtLife.Clear()
lstResult.ClearSelected()
Description = CStr(txtDescription.Text)
Year = CStr(txtYear.Text)
Life = CStr(txtLife.Text)
SLMDepreciation = CStr(SLMD())
lstResult.Items.Add("Description: " & Description)
lstResult.Items.Add("Year of purchase: " & Year)
lstResult.Items.Add("Cost: " & FormatCurrency(CStr(txtCost.Text), 2))
lstResult.Items.Add("Estimated life: " & Life)
lstResult.Items.Add("Method of depreciation: " & SLMText)
End Sub
Function SLMD() As Double
Dim Salvage_Value As Integer = 0
Dim Life As String = CStr(txtLife.Text)
Dim Cost As String = CStr(txtCost.Text)
SLMD = (CDbl(txtCost.Text) - Salvage_Value) / CDbl(Life)
Return SLMD
End Function
End Class
错误在“SLMD = (CDbl(txtCost.Text) - Salvage_Value) / CDbl(Life)”处不断发生,但是当我改变周围的东西时,它开始指向我用相同错误改变的东西。
如果有人可以帮助我,我将永远欠债......