2017-08-14 48 views
0

我有一個數組填充了24個數字我想所有的數字要加在一起,然後顯示在文本框中。這是我爲這個數組創建的代碼。但我不確定如何將數組中的所有數字一起添加。感謝您的時間。在數組中添加所有數字

'Calculating distances 
    Dim Game As String 

    Game = txtGameAdd.Text 

    SystemValueGame = SystemValueGame + 1 
    TotalGames(SystemValueGame) = Game 
    txtGameAdd.Text = "" 
    txtGameAdd.Focus() 

    'Keeping count with lables' 

    lblAmountNum.Text = SystemValueGame 

    'Double Checking SystemValue' 

    If SystemValueGame = 24 Then 

     'notify when array is full' 

     MsgBox("Entered Max Amount Of Surnames", MsgBoxStyle.Information) 

     txtGameAdd.Text = " " 
     txtGameAdd.Enabled = False 

    End If 
+0

嘗試使用[For Each](https://docs.microsoft.com/en-us/dotnet/visual-basic/language-reference/statements/for-each-next-statement) –

+0

什麼是數組? – ZAhmed

+0

該數組是TotalGames – jdavies

回答

1

你或許可以做一些非常相似的事情。

Dim ar As Array = Nothing 
    Dim sum As Integer = 0 

    For Each st As String In ar 
     sum = sum + CInt(st) 
    Next 

類似這樣的方法將訪問數組的每個值並將它們相加。

+0

謝謝你。尋求幫助 – jdavies

相關問題