vb.net算术运算导致溢出错误

时间:2017-09-03 10:34:16

标签: vb.net

我试图将一个8位数字的每个值(称为" d8")转换为其ASCII值,然后我有8个整数。然后我想将它们一起添加以形成一个整数并将此值显示在OffFac.Text中。但它始终显示此错误"算术运算导致溢出"。

Dim d8 As String
Dim Step2 As Integer
d8 = DEight.Text
Dim RandomNumber2C As Char = d8.Substring(0, 1)
Dim RandomNumber22C As Char = d8.Substring(1, 1)
Dim RandomNumber32C As Char = d8.Substring(2, 1)
Dim RandomNumber42C As Char = d8.Substring(3, 1)
Dim RandomNumber52C As Char = d8.Substring(4, 1)
Dim RandomNumber62C As Char = d8.Substring(5, 1)
Dim RandomNumber72C As Char = d8.Substring(6, 1)
Dim RandomNumber82C As Char = d8.Substring(7, 1)
Dim RandomNumberX As String = Asc(Mid(RandomNumber2C, 1))
Dim RandomNumber2X As String = Asc(Mid(RandomNumber22C,1))
Dim RandomNumber3X As String = Asc(Mid(RandomNumber32C, 1))
Dim RandomNumber4X As String = Asc(Mid(RandomNumber42C, 1))
Dim RandomNumber5X As String = Asc(Mid(RandomNumber52C, 1))
Dim RandomNumber6X As String = Asc(Mid(RandomNumber62C, 1))
Dim RandomNumber7X As String = Asc(Mid(RandomNumber72C, 1))
Dim RandomNumber8X As String = Asc(Mid(RandomNumber82C, 1))
Dim RandomNumberXX As String = CLng(RandomNumberX)
Dim RandomNumber2XX As String = CLng(RandomNumber2X)
Dim RandomNumber3XX As String = CLng(RandomNumber3X)
Dim RandomNumber4XX As String = CLng(RandomNumber4X)
Dim RandomNumber5XX As String = CLng(RandomNumber5X)
Dim RandomNumber6XX As String = CLng(RandomNumber6X)
Dim RandomNumber7XX As String = CLng(RandomNumber7X)
Dim RandomNumber8XX As String = CLng(RandomNumber8X)

Step2 = RandomNumberXX + RandomNumber2XX + RandomNumber3XX + RandomNumber4XX + RandomNumber5XX + RandomNumber6XX + RandomNumber7XX + RandomNumber8XX
Step2 = OffFac.Text

1 个答案:

答案 0 :(得分:0)

您正在尝试连接(将一系列字符串相互附加)一系列数字,这些数字是输入到文本框中的数字字符的ascii值。

使用字符串" 12345678"你得到以下。

" 49" +" 50" +" 51" +" 52" +" 53" +" 54" +" 55" +" 56" =" 4950515253545556"

编号4950515253545556太大而无法分配给整数。

此外,您的上一个作业声明应为

OffFac.text = step2

您可能想要做这样的事情

Dim RandomNumberX As Integer = Asc(Mid(RandomNumber2C, 1))
Dim RandomNumber2X As Integer = Asc(Mid(RandomNumber22C, 1))
Dim RandomNumber3X As Integer = Asc(Mid(RandomNumber32C, 1))
Dim RandomNumber4X As Integer = Asc(Mid(RandomNumber42C, 1))
Dim RandomNumber5X As Integer = Asc(Mid(RandomNumber52C, 1))
Dim RandomNumber6X As Integer = Asc(Mid(RandomNumber62C, 1))
Dim RandomNumber7X As Integer = Asc(Mid(RandomNumber72C, 1))
Dim RandomNumber8X As Integer = Asc(Mid(RandomNumber82C, 1))
Dim RandomNumberXX As Integer = CLng(RandomNumberX)
Dim RandomNumber2XX As Integer = CLng(RandomNumber2X)
Dim RandomNumber3XX As Integer = CLng(RandomNumber3X)
Dim RandomNumber4XX As Integer = CLng(RandomNumber4X)
Dim RandomNumber5XX As Integer = CLng(RandomNumber5X)
Dim RandomNumber6XX As Integer = CLng(RandomNumber6X)
Dim RandomNumber7XX As Integer = CLng(RandomNumber7X)
Dim RandomNumber8XX As Integer = CLng(RandomNumber8X)