Arrays
 

Arrays are using for store similar data types grouping as a single unit. We can access Array elements by its numeric index.

Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
Dim i As Integer
Dim week(6) As String
week(0) = "Sunday"
week(1) = "Monday"
week(2) = "Tuesday"
week(3) = "Wednesday"
week(4) = "Thursday"
week(5) = "Friday"
week(6) = "Saturday"

For i = 0 To week.Length - 1
MsgBox(week(i))
Next

End Sub
End Class

When you execute this program you will get the Days in a Week .

Dim week(6) As String

The above statements means that , an Array named as week declared as a String type and it can have the capability of seven String type values.

week(0) = "Sunday"

week(1) = "Monday"

In the above statement , we initialize the values to the String Array. week(0) = "Sunday" means , we initialize the first value of Array as "Sunday" ,

Dim weekName as String = week(1)

We can access the Arrays elements by providing its numerical index, the above statement we access the second value from the week Array.

In the following program , we declare an Array "week" capability of seven String values and assigns the seven values as days in a week . Next step is to retrieve the elements of the Array using a For loop. For finding the end of an Array we used the Length function of Array Object.

(c) Shilpa Sayura Foundation 2006-2017