2017-09-03 82 views
-1

我試圖將八位數字串的每個值,稱爲「d8」,到它的ASCII值,然後我有8個整數。然後我想將它們加在一起形成一個整數並將此值顯示到OffFac.Text中。但它總是顯示這個錯誤「算術運算導致溢出」。vb.net算術運算導致溢出錯誤

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 
+0

你應該研究你的錯誤,但......以要求更高的層次來看,這看起來像ASCII代碼單元(恰好是字節)的校驗和。因此,'Dim byte2Long = Function(b As Byte)CLng(b):Dim longSum = Encoding.ASCII.GetBytes(d8).Select(byte2Long).Sum()'在編碼中,清晰度爲王,少爲多,對問題陳述的追溯是黃金。 –

回答

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) 
相關問題