Looping through Attay in VB.NET

n this article you will learn how to use for loop to work with arrays
  • 1861

This example shows you how to put values in array by using for loop and than calculate sum and average of the values of array and just simply shows all the value: total numbers in the array , sum and average of the values in a single message box.

     Example Code   

        Imports System.Windows.Forms
          Module Module1
               Sub Main()
                    Dim number(9) As Integer
                    For
i As Integer = 0 To number.Length - 1
                        number(i) = i
                    Next
                    Dim
numbersString As String = ""
                    For i As Integer = 0 To number.Length - 1
                        numbersString &= number(i).ToString &
" "
                    Next
                    Dim
sum As Integer = 0
                        For i As Integer = 0 To number.Length - 1
                        sum += number(i)
                    Next
                    Dim
average As Integer = sum / number.Length
                    MessageBox.Show("All numbers: " & numbersString & vbCrLf & "Sum: " & sum & vbCrLf & "Average: " & average, "Calculation")
               End Sub
          End
Module

         OUTPUT 

12.gif
            

Categories

More Articles

© 2019 DotNetHeaven. All rights reserved.