在数组中添加所有数字

时间:2017-08-14 08:55:47

标签: arrays vb.net

我有一个填充了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

1 个答案:

答案 0 :(得分:1)

你可能会做一些非常类似的事情。

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

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

这样的方法将访问数组的每个值并将它们一起添加。