[英]Error `Conversion from string “” to type 'Double' is not valid` in VB.net
我正在嘗試編寫計算double值,但是它出現一個錯誤,指出Conversion from string "" to type 'Double' is not valid.
Dim x As Integer = "8"
Dim f As Integer = "100"
Dim z As Double
Dim r As Double
Dim Nw As Double
Dim W As Double
Dim Was As Double
Dim Nwas As Double
Dim cost As Double
Dim IBLP As Double
Dim sale As Double
Dim sale1 As Double
Dim last As Double
Nw = CDbl(txtnetwasage.Text)
W = CDbl(txtweight.Text)
Was = CDbl(txtwastage.Text)
Nwas = CDbl(txtnetweight.Text)
cost = CDbl(txtcost.Text)
IBLP = CDbl(txtwastage.Text)
sale = CDbl(txtsale.Text)
sale1 = CDbl(txtvsale1.Text)
last = Double.Parse(txtlast.Text)
Nw = (W) * (Was)
Nwas = (W) + (Nwas)
cost = (IBLP) / (x) * (Nwas)
z = (cost) / (f) * (sale)
sale = (z) + (cost)
r = (cost) / (f) * (sale1)
last = (r) + (cost)
這是Codexer在注釋中建議的Double.TryParse()
示例:
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim W As Double
If Not Double.TryParse(txtweight.Text, W) Then
MessageBox.Show("Value: " & txtweight.Text, "Invalid Weight")
txtweight.Focus()
txtweight.SelectAll()
Exit Sub
End If
Dim Nwas As Double
If Not Double.TryParse(txtnetweight.Text, W) Then
MessageBox.Show("Value: " & txtnetweight.Text, "Invalid Net Weight")
txtnetweight.Focus()
txtnetweight.SelectAll()
Exit Sub
End If
' ... etc ...
' ... everything is good, perform your calculations ...
End Sub
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.