shinobi1173
New member
- Joined
- Jul 15, 2012
- Messages
- 2
- Programming Experience
- Beginner
OK, I keep getting this annoying message (even thought it is my fault), "Conversion from string "" to type 'Double' is not valid." I get this message when I am debugging in VB 2010 Express and I hit the "SLM" button. What the heck does this mean and what am I doing wrong?!?!
My code:
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 = 1
Dim Life As String = CStr(txtLife.Text)
Dim Cost As String = CStr(txtCost.Text)
SLMD = (CDbl(Cost) - Salvage_Value) / CDbl(Life)
Return SLMD
End Function
End Class
The error keeps happening at the "SLMD = (CDbl(txtCost.Text) - Salvage_Value) / CDbl(Life)" but when I change things around, it starts pointing at the things that I change with the same error.
If anyone can help me out, I will be in forever debt...
My code:
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 = 1
Dim Life As String = CStr(txtLife.Text)
Dim Cost As String = CStr(txtCost.Text)
SLMD = (CDbl(Cost) - Salvage_Value) / CDbl(Life)
Return SLMD
End Function
End Class
The error keeps happening at the "SLMD = (CDbl(txtCost.Text) - Salvage_Value) / CDbl(Life)" but when I change things around, it starts pointing at the things that I change with the same error.
If anyone can help me out, I will be in forever debt...