当我将两个字符串更改为double时,然后减去它们,答案始终为0.有没有人知道解决此问题的方法?
Dim TotalCashNum As Double
Dim InsertCoinNum As Double
Dim NewTotalCash As Double
InsertCoinsTextBox.Text = Convert.ToDouble(InsertCoinNum)
TotalCash.Text = Convert.ToDouble(TotalCashNum)
NewTotalCash = TotalCashNum - InsertCoinNum
MsgBox(NewTotalCash)
提前致谢
答案 0 :(得分:2)
这些行错了:
InsertCoinsTextBox.Text = Convert.ToDouble(InsertCoinNum)
TotalCash.Text = Convert.ToDouble(TotalCashNum)
应该是
InsertCoinNum = CDbl(InsertCoinsTextBox.Text )
TotalCashNum = CDbl(TotalCash.Text)
答案 1 :(得分:1)
您正在将文本框的值分配给错误的变量。
应该是:
Dim TotalCashNum As Double
Dim InsertCoinNum As Double
Dim NewTotalCash As Double
InsertCoinNum = CDbl(InsertCoinsTextBox.Text )
TotalCashNum = CDbl(TotalCash.Text)
NewTotalCash = TotalCashNum - InsertCoinNum