0

I have a Array filled with 24 numbers an I would like all the numbers to be added together and then displayed in a text box. This is the code I have created for the array. but I'm not sure how to add all the numbers in the array together. thank You for Your Time.

    '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
8
  • Try with For Each Commented Aug 14, 2017 at 8:57
  • what is the array ? Commented Aug 14, 2017 at 8:57
  • The array is TotalGames Commented Aug 14, 2017 at 8:59
  • 1
    Use TotalGames.Sum() Commented Aug 14, 2017 at 9:03
  • 1
    is that all really. awesome thank you for the life saver. Commented Aug 14, 2017 at 9:04

1 Answer 1

1

You could probably do something very similar to this.

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

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

A method such as this, will access every value of the array and add them together.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.