简体   繁体   English

VB.net将字符串转换为具有高价值的整数

[英]VB.net Convert String to Integer with high value

I am using VB.net I Need Help what I want is for it to convert the string to integer as shown. 我正在使用VB.net,我需要帮助,我想要的是将它转换为整数,如图所示。

    Dim txt12(7) As String

    Dim txt12toint As Integer
    txt12(0) = "048048048048"
    If txt12(0).Substring(0, 1) = 0 Then
        txt12(0) = txt12(0).Substring(1, 11)
    End If
    txt12toint = Convert.ToInt64(txt12(0))

However there is always a message stating : OverflowException was unhandled arithmetic operation resulted in an overflow Makesure you are not dividing by zero 但是总是有一条消息指出:OverflowException是未处理的算术运算导致溢出确保您没有被零除

I even tried: 我什至尝试:

Cint(txt12(0))

and

Convert.toint32(txt12(0))

but the error to this is the characters are either too long or too short. 但是这样做的错误是字符太长或太短。 because int32 is up to 2,147,483,647 one Please if anyone can help thank you in advance 因为int32最多可以有2,147,483,647个,请先帮助一下,谢谢

Just declare txt12toint as Long: 只需将txt12toint声明为Long:

Dim txt12toint As Long

This is because 48048048048 exceeds the maximum value for an Integer. 这是因为48048048048超出了整数的最大值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM