如何解决我在vb.net上的代码在变值?
这是我启动vb.net时遇到的问题: 从字符串“”到类型“整型”的转换无效 我想要的是当我在quantity文本框中输入一个数字时自动计算TotalPrice文本框如何解决我在vb.net上的代码在变值?,vb.net,Vb.net,这是我启动vb.net时遇到的问题: 从字符串“”到类型“整型”的转换无效 我想要的是当我在quantity文本框中输入一个数字时自动计算TotalPrice文本框 局部变量i被声明为整数 QuantityTextBox.Text是一个字符串 您无法从字符串转换为整数,因为虽然字符串“123”可以很容易地转换为整数,但字符串“abc”不能 因此,您必须通过调用convert.ToInt32或Int32.Parse 这样做: Private Sub QuantityTextBox_TextCha
- 局部变量
被声明为i
整数
是一个QuantityTextBox.Text
字符串
- 您无法从
转换为字符串
,因为虽然字符串“123”可以很容易地转换为整数,但字符串“abc”不能整数
- 因此,您必须通过调用
或convert.ToInt32
Int32.Parse
Private Sub QuantityTextBox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles QuantityTextBox.TextChanged
Dim i As Integer
Dim total As Integer
Dim PPrice As Integer
i = QuantityTextBox.Text
PPrice = ProductPriceTextBox.Text
total = Integer.Parse(i) * Integer.Parse(PPrice)
TotalPriceTextBox.Text = total
End Sub
输入字符串的格式不正确。现在这是我的error@KrissyNoriega我建议您阅读MSDN文档,了解
如何解析方法单词。错误发生在哪一行?请补充你的问题。
i = Integer.Parse( QuantityTextBox.Text )
pPrice = Integer.Parse( ProductPriceTextBox.Text )
total = i * pPrice
TotalPriceTextBox.Text = total.ToString("C")