好的,所以我创建了一个计算千瓦成本的程序,每当我选择3个设备中的2个时,我收到此错误消息
未处理的类型' System.FormatException'发生在mscorlib.dll中 附加信息:输入字符串的格式不正确。
这是完整的代码,我不知道哪里出错了。请帮忙?
Public Class Form1
Private RunningTotal As Double
Private Sub btnCalculate_Click(sender As Object, e As EventArgs) Handles btnCalculate.Click
Dim kw As Double = Convert.ToDouble(txtKW.Text)
Dim hpd As Double = Convert.ToDouble(txtHPD.Text)
Dim kwpd As Double = Convert.ToDouble(txtKWPH.Text)
Dim gal As Double = Convert.ToDouble(txtGallon.Text)
Dim cpg As Double = Convert.ToDouble(txtCostPerGal.Text)
Dim result As Double = kw * hpd * kwpd * gal * cpg
lblResults.Text = result.ToString("C")
RunningTotal = RunningTotal + result
lblRunning.Text = RunningTotal.ToString("C")
kw = Convert.ToDouble(txtKW.Text)
hpd = Convert.ToDouble(txtHPD.Text)
kwpd = Convert.ToDouble(txtKWPH.Text)
gal = Convert.ToDouble(txtGallon.Text)
cpg = Convert.ToDouble(txtCostPerGal.Text)
End Sub
Private Sub QuitToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles QuitToolStripMenuItem.Click
Close()
End Sub
Private Sub AboutToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles AboutToolStripMenuItem.Click
MessageBox.Show("This program was made by BD")
End Sub
Private Sub txtKW_TextChanged(sender As Object, e As EventArgs) Handles txtKW.TextChanged
If IsNumeric(txtKW.Text) = True Then
If (txtKW.Text = "0123456789") Then
lblResults.Text = DialogResult.ToString("c")
End If
Else
MessageBox.Show("Please enter a number")
End If
End Sub
Private Sub txtHPD_TextChanged(sender As Object, e As EventArgs) Handles txtHPD.TextChanged
If IsNumeric(txtHPD.Text) = True Then
If (txtHPD.Text = "0123456789") Then
lblResults.Text = DialogResult.ToString("c")
End If
Else
MessageBox.Show("Please enter a number")
End If
End Sub
Private Sub txtKWPH_TextChanged(sender As Object, e As EventArgs) Handles txtKWPH.TextChanged
If IsNumeric(txtKWPH.Text) = True Then
If (txtKWPH.Text = "0123456789") Then
lblResults.Text = DialogResult.ToString("c")
End If
Else
MessageBox.Show("Please enter a number")
End If
End Sub
Private Sub HelpToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles HelpToolStripMenuItem.Click
MessageBox.Show("This program was designed to help you determine your cost of appliances, simply enter the amount of kilowatts your appliance uses, how many hours per day you use your appliance, and the cost per kilowatt hour then click calculate.")
End Sub
Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox1.SelectedIndexChanged
Dim index As Integer = ComboBox1.SelectedIndex
If (index = 2) Then
txtGallon.Visible = True
txtCostPerGal.Visible = True
Else
txtGallon.Visible = False
txtCostPerGal.Visible = False
End If
End Sub
Private Sub Label2_Click(sender As Object, e As EventArgs) Handles lblGallons.Click
End Sub
Private Sub txtGallon_TextChanged(sender As Object, e As EventArgs) Handles txtGallon.TextChanged
If IsNumeric(txtGallon.Text) = True Then
If (txtGallon.Text = "0123456789") Then
lblResults.Text = DialogResult.ToString("c")
End If
Else
MessageBox.Show("Please enter a number")
End If
End Sub
Private Sub txtCostPerGal_TextChanged(sender As Object, e As EventArgs) Handles txtCostPerGal.TextChanged
If IsNumeric(txtCostPerGal.Text) = True Then
If (txtCostPerGal.Text = "0123456789") Then
lblResults.Text = DialogResult.ToString("c")
End If
Else
MessageBox.Show("Please enter a number")
End If
End Sub
Private Sub ListBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ListBox1.SelectedIndexChanged
End Sub
End Class