How do I convert from a string to an integer in Visual Basic?

后端 未结 7 1056
死守一世寂寞
死守一世寂寞 2020-12-15 15:06

How do I convert from a string to an integer? Here\'s what I tried:

Price = CInt(Int(txtPrice.Text))

I took out the Int and I

7条回答
  •  眼角桃花
    2020-12-15 15:28

    Use

    Convert.toInt32(txtPrice.Text)
    

    This is assuming VB.NET.

    Judging by the name "txtPrice", you really don't want an Integer but a Decimal. So instead use:

    Convert.toDecimal(txtPrice.Text)
    

    If this is the case, be sure whatever you assign this to is Decimal not an Integer.

提交回复
热议问题