字符串转换不起作用

时间:2017-02-28 14:43:40

标签: vb.net visual-studio-2015

我试图找到这些项目的小计。当我运行它时,它表示qty变量和价格变量字符串没有被转换。当我转换它们时,我仍然会收到一个错误,说格式有问题。我正在文本框中输入qtys,它们不是预填充的。请帮忙

  Private Sub Btn1_Click(sender As Object, e As EventArgs) Handles Btn1.Click
    Dim blackprice As Single = 43.0
    Dim classyheelprice As Single = 48.95
    Dim redprice As Single = 35.95
    Dim weddingprice As Single = 155.65
    Dim sportsprice As Single = 50
    Dim qty1 As Integer = TxtBox1.Text
    Dim qty2 As Integer = TxtBox3.Text
    Dim qty3 As Integer = TxtBox4.Text
    Dim qty4 As Integer = TxtBox5.Text
    Dim qty5 As Integer = TxtBox6.Text
    Dim price1 As Single = Convert.ToSingle(TxtBox2.Text)
    Dim price2 As Single = Convert.ToSingle(TxtBox7.Text)
    Dim price3 As Single = Convert.ToSingle(TxtBox10.Text)
    Dim price4 As Single = Convert.ToSingle(TxtBox9.Text)
    Dim price5 As Single = Convert.ToSingle(TxtBox8.Text)


    price1 = qty1 * blackprice
    Price2 = qty2 * classyheelprice
    Price3 = qty3 * redprice
    Price4 = qty4 * weddingprice
    Price5 = qty5 * sportsprice
    Shoestotal = price1 + price2 + price3 + price4 + price5
    TxtBox11.Text = Shoestotal

错误1:附加信息:从字符串转换""输入'整数'无效。 错误2:附加信息:输入字符串的格式不正确。

1 个答案:

答案 0 :(得分:0)

此行存在问题:

Dim qty1 As Integer = TxtBox1.Text

你应该施展它:

Dim qty1 As Integer = Integer.Parse(textBox1.Text)