Table of Contents hide
Example : An Array Examples in VB .Net or Program to display only first and last integer values from statically stored Array value through Module via Console Application.
Imports System
Module Module1
    Sub Main()

        Dim i As Integer
        Dim arr() As Integer = {10, 20, 30, 40, 50}
        Console.WriteLine("The values stored in an array is: ")

        Console.Write(arr(0))
        Console.Write(" ")
        Console.Write(arr(1))


        Console.WriteLine()
        Console.WriteLine("Press any key to exit from output screen...")
        Console.ReadLine()
    End Sub
End Module
Example : An Array Examples in VB .Net or Program to display all the integer values in different ways as stored in an Array statically through Module via Console Application.
Imports System
Module Module1
    Sub Main()

        Dim i As Integer        
        Dim arr() As Integer = {10, 20, 30, 40, 50}
        Console.WriteLine("The values stored in an array is: ")
        For i = 0 To arr.Length - 1
            Console.WriteLine(arr(i))
        Next

        Console.WriteLine()
        Console.WriteLine("Press any key to exit from output screen...")
        Console.ReadLine()
    End Sub
End Module

Output :
The values stored in an array is:
10
20
30
40
50

Press any key to exit from output screen...

-----------------  OR  -----------------

Imports System
Module Module1
    Sub Main()

        Dim i As Integer
        Dim arr() As Integer = {10, 20, 30, 40, 50}
        Console.WriteLine("The values stored in an array is: ")
        For i = 0 To arr.Length - 1
            Console.Write(arr(i))
            Console.Write(" ")
        Next

        Console.WriteLine()
        Console.WriteLine("Press any key to exit from output screen...")
        Console.ReadLine()
    End Sub
End Module

Output :
The values stored in an array is:
10 20 30 40 50

Press any key to exit from output screen...

-----------------  OR  -----------------

Imports System
Module Module1
    Sub Main()

        Dim arr As Integer() = New Integer(5) {10, 20, 30, 40, 50, 60}
        'Dim arr As Integer() = New Integer() {10, 20, 30, 40, 50, 60}

        Console.WriteLine("The values stored in array are : ")
        For i = 0 To arr.Length - 1
            Console.WriteLine(arr(i))
        Next

        Console.WriteLine()
        Console.WriteLine("Press any key to exit from output screen...")
        Console.ReadLine()
    End Sub
End Module

Output :
The values stored in an array is:
10
20
30
40
50

Press any key to exit from output screen...

-----------------  OR  -----------------

Imports System
Module Module1
    Sub Main()

        Dim i As Integer
        Dim arr As Integer()
        arr = New Integer() {10, 20, 30, 40, 50}
        Console.WriteLine("The values stored in an array is: ")
        For i = 0 To arr.Length - 1
            Console.WriteLine(arr(i))
        Next

        Console.WriteLine()
        Console.WriteLine("Press any key to exit from output screen...")
        Console.ReadLine()
    End Sub
End Module

Output :
The values stored in an array is:
10
20
30
40
50

Press any key to exit from output screen...

-----------------  OR  -----------------

Imports System
Module Module1
    Sub Main()

        Dim i As Integer
        Dim arr(0 To 4) As Integer  'Fixed Size Array
        arr(0) = 10
        arr(1) = 20
        arr(2) = 30
        arr(3) = 40
        arr(4) = 50
        Console.WriteLine("The values stored in an array is: ")
        For i = 0 To arr.Length - 1
            Console.WriteLine(arr(i))
        Next

        Console.WriteLine()
        Console.WriteLine("Press any key to exit from output screen...")
        Console.ReadLine()
    End Sub
End Module

Output :
The values stored in an array is:
10
20
30
40
50

Press any key to exit from output screen...
Example : A VB .Net Program to display all the Single Character values stored in an Array statically through Module via Console Application.
Imports System
Module Module1
    Sub Main()

        Dim i As Integer
        Dim arr() As Char = {"A", "B", "C", "D", "E"}

        Console.WriteLine("The values stored in an array is: ")
        For i = 0 To arr.Length - 1
            Console.WriteLine(arr(i))
        Next

        Console.WriteLine()
        Console.WriteLine("Press any key to exit from output screen...")
        Console.ReadLine()
    End Sub
End Module

Output :
The values stored in an array is:
A
B
C
D
E

Press any key to exit from output screen...

-----------------  OR  -----------------

Imports System
Module Module1
    Sub Main()

        Dim i As Integer
        Dim arr(2) As Char
        arr(0) = "A"
        arr(1) = "B"
        arr(2) = "C"

        Console.WriteLine("The values stored in an array is: ")
        For i = 0 To arr.Length - 1
            Console.WriteLine(arr(i))
        Next

        Console.WriteLine()
        Console.WriteLine("Press any key to exit from output screen...")
        Console.ReadLine()
    End Sub
End Module

Output:
The values stored in an array is:
A
B
C

Press any key to exit from output screen...
Example : A VB .Net Program to display all the String values stored in an Array statically through Module via Console Application.
Imports System
Module Module1
    Sub Main()
        Dim i As Integer       

        Dim arr() As String = {"India", "America", "France", "Russia", "Israel"}

        Console.WriteLine("The values stored in an array is: ")
        For i = 0 To arr.Length - 1
            Console.WriteLine(arr(i))
        Next

        Console.WriteLine()
        Console.WriteLine("Press any key to exit from output screen...")
        Console.ReadLine()
    End Sub
End Module

Output :
The values stored in an array is:
India
America
France
Russia
Israel

Press any key to exit from output screen...
Example : A VB .Net Program to display all the Object values/Misc. Characters are stored in an Array statically through a Module via the Console Application.
Imports System
Module Module1
    Sub Main()

        Dim i As Integer
        Dim arr() As Object = {"India", 50, "S400", 5000.32, "600"}

        Console.WriteLine("The values stored in an array is: ")
        For i = 0 To arr.Length - 1
            Console.WriteLine(arr(i))
        Next

        Console.WriteLine()
        Console.WriteLine("Press any key to exit from output screen...")
        Console.ReadLine()
    End Sub
End Module

Output :
The values stored in an array is:
India
50
S400
5000.32
600

Press any key to exit from output screen...
Example : A VB .Net Program to display all the values stored in an Array statically using For Each Loop/Without any help of Index through Module via Console Application.
Imports System
Module Module2
    Sub Main()
        Dim arr() As Integer = {1, 2, 3, 4, 5}
        Dim i As Integer

        For Each i In arr
            Console.WriteLine("Value of index {0} is {1}", i - 1, i)
        Next
        Console.WriteLine("Press any key to exit from output...")
        Console.ReadLine()
    End Sub
End Module

Output :
Value of index 0 is 1
Value of index 1 is 2
Value of index 2 is 3
Value of index 3 is 4
Value of index 4 is 5
Press any key to exit from output...
Example : A VB .Net Program to display the Size/Count of the length of an array in different ways through Module via Console Application.
Imports System
Module Module1
    Sub Main()

        Dim arr1() As Char = {"A", "B", "C", "D"}

        Dim arr2(2) As Char
        arr2(0) = "A"
        arr2(1) = "B"
        arr2(2) = "C"

        Dim arr3() As Integer = {10, 20}

        Dim arr4() As String = {"India", "America", "France", "Russia", "Israel", "UK"}

        Dim arr5() As Object = {"India", 50, "S400", 5000.32, "600"}

        Console.WriteLine("The Size/Length of different array are : ")
        Console.WriteLine(arr1.Length)
        Console.WriteLine(arr2.Length)
        Console.WriteLine(arr3.Length)
        Console.WriteLine(arr4.Length)
        Console.WriteLine(arr5.Length)

        Console.WriteLine()
        Console.WriteLine("Press any key to exit from output screen...")
        Console.ReadLine()
    End Sub
End Module

Output: 
The Size/Length of different array are :
4
3
2
6
5

Press any key to exit from output screen...
Example : A VB .Net Program to convert a String into Single Characters of an array through Module via Console Application.
Imports System
Module Module1
    Sub Main()

        Dim Str As String = "Welcome"

        Dim arr() As Char = Str.ToCharArray()

        For Each x As Char In arr
            Console.WriteLine(x)
        Next

        Console.WriteLine()
        Console.WriteLine("Press any key to exit from output screen...")
        Console.ReadLine()
    End Sub
End Module

Output:
W
e
l
c
o
m
e

Press any key to exit from output screen...
Example : A VB .Net Program to accept integer values from users at run time/dynamically in a one-dimensional array through keyboard and display all of them through Module via Console Application.
Imports System
Module Module1
    Sub Main()

        Dim arr(5) As Integer
        'Dim arr As Integer() = New Integer(5) {}

        Console.WriteLine("Enter the 6 Array elements")
        Console.WriteLine()

        For i As Integer = 0 To 5
            Console.Write("Enter the array {0} value for Index {1}: ", i + 1, i)
            arr(i) = Console.ReadLine()
        Next

        Console.WriteLine()
        Console.WriteLine("The stored 6 array elements are : ")
        For j As Integer = 0 To 5
            Console.WriteLine(arr(j))
        Next

        Console.WriteLine()
        Console.WriteLine("Press any key to exit from output screen...")
        Console.ReadLine()
    End Sub
End Module

Output:
Enter the 6 Array elements

Enter the array 1 value for Index 0: 10
Enter the array 2 value for Index 1: 20
Enter the array 3 value for Index 2: 30
Enter the array 4 value for Index 3: 40
Enter the array 5 value for Index 4: 50
Enter the array 6 value for Index 5: 60

The stored 6 array elements are :
10
20
30
40
50
60

Press any key to exit from output screen...
Example : A VB .Net Program to display all the statically stored values from Two Dimensional Array through Module via Console Application.
Imports System
Module Module1
    Sub Main()

        Dim tda(,) As Integer = {{10, 20}, {30, 40}, {50, 60}}        

        Console.WriteLine("The stored 6 array elements in 3 rows and 2 columns are : ")
        Console.WriteLine()
        For i As Integer = 0 To 2
            For j As Integer = 0 To 1
                Console.WriteLine("The values at index {0}, {1} = {2}", i, j, tda(i, j))
            Next j
        Next i

        Console.WriteLine()
        Console.WriteLine("Press any key to exit from output screen...")
        Console.ReadLine()
    End Sub
End Module

Output:
The stored 6 array elements in 3 rows and 2 columns are :

The values at index 0, 0 = 10
The values at index 0, 1 = 20
The values at index 1, 0 = 30
The values at index 1, 1 = 40
The values at index 2, 0 = 50
The values at index 2, 1 = 60

Press any key to exit from output screen...
Example : A VB .Net Program to display all the user-accepted dynamic values from a two-dimensional Array through a Module via a Console Application.
Imports System
Module Module1
    Sub Main()

        Dim tda(3, 2) As Integer

        Console.WriteLine("Enter 12 array elements in 4 rows and 3 columns are : ")
        Console.WriteLine()
        For i As Integer = 0 To 3
            For j As Integer = 0 To 2
                tda(i, j) = Console.ReadLine()
            Next j
        Next i
        Console.WriteLine()

        Console.WriteLine("The stored 12 array elements in 4 rows and 3 columns are : ")
        For i As Integer = 0 To 3
            For j As Integer = 0 To 2
                Console.WriteLine("The values at index {0}, {1} = {2}", i, j, tda(i, j))
            Next j
        Next i

        Console.WriteLine()
        Console.WriteLine("Press any key to exit from output screen...")
        Console.ReadLine()
    End Sub
End Module

Output:

10
20
30
40
50
60
70
80
90
100
110
120

The stored 12 array elements in 4 rows and 3 columns are :
The values at index 0, 0 = 10
The values at index 0, 1 = 20
The values at index 0, 2 = 30
The values at index 1, 0 = 40
The values at index 1, 1 = 50
The values at index 1, 2 = 60
The values at index 2, 0 = 70
The values at index 2, 1 = 80
The values at index 2, 2 = 90
The values at index 3, 0 = 100
The values at index 3, 1 = 110
The values at index 3, 2 = 120

Press any key to exit from output screen...

Loading


0 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.