July 15, 2015

Sample ARRAY (Microsoft Visual Studio)

Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCons_Val.Click
        Dim arr(5)
        arr(0) = "1"
        arr(1) = "VBScript"
        arr(2) = 100
        arr(3) = 2.45
        arr(4) = #10/7/2013#

        MsgBox("Value stored in Array Index 0 : " & arr(0))
        MsgBox("Value stored in Array Index 1 : " & arr(1))
        MsgBox("Value stored in Array Index 2 : " & arr(2))
        MsgBox("Value stored in Array Index 3 : " & arr(3))
        MsgBox("Value stored in Array Index 4 : " & arr(4))


    End Sub

    Private Sub btnArr2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnArr2.Click
        Dim array(2, 3) As Object
        array(0, 0) = "Apple"
        array(0, 1) = "Orange"
        array(0, 2) = "Grapes"
        array(0, 3) = "Mango"
        array(1, 0) = "pineapple"
        array(1, 1) = "Cucumber"
        array(1, 2) = "beans"
        array(1, 3) = "carrot"
        array(2, 0) = "Sandwitch"
        array(2, 1) = "coffee"
        array(2, 2) = "nuts"
        array(2, 3) = "Carrot"

        MsgBox("Value stored in Array Index 0,1 : " & array(0, 1))
        MsgBox("Value stored in Array Index 2,2 : " & array(2, 2))

    End Sub

    Private Sub btnArr3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnArr3.Click
        Dim a() As Object
        Dim i = 0
        ReDim a(5)
        a(0) = "XYZ"
        a(1) = 41.25
        a(2) = 22

        ReDim Preserve a(7)
        For i = 3 To 7
            a(i) = i

        Next
        For i = 0 To UBound(a)
            MsgBox(a(i))
        Next

    End Sub
End Class