2017-08-14 94 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