如何解决我在vb.net上的代码在变值?

如何解决我在vb.net上的代码在变值?,vb.net,Vb.net,这是我启动vb.net时遇到的问题: 从字符串“”到类型“整型”的转换无效 我想要的是当我在quantity文本框中输入一个数字时自动计算TotalPrice文本框 局部变量i被声明为整数 QuantityTextBox.Text是一个字符串 您无法从字符串转换为整数,因为虽然字符串“123”可以很容易地转换为整数,但字符串“abc”不能 因此,您必须通过调用convert.ToInt32或Int32.Parse 这样做: Private Sub QuantityTextBox_TextCha

这是我启动vb.net时遇到的问题:

从字符串“”到类型“整型”的转换无效

我想要的是当我在quantity文本框中输入一个数字时自动计算TotalPrice文本框

  • 局部变量
    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")