0% found this document useful (0 votes)
2 views

Arrays in VB

The document provides a tutorial on creating and accessing arrays in Visual Basic (VB), including examples for both integer and string arrays. It demonstrates how to initialize an integer array with five elements and access them using a loop, as well as how to create and access a string array. The code can be run in an IDE or online compiler to visualize the array operations.

Uploaded by

faithndlovu489
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Arrays in VB

The document provides a tutorial on creating and accessing arrays in Visual Basic (VB), including examples for both integer and string arrays. It demonstrates how to initialize an integer array with five elements and access them using a loop, as well as how to create and access a string array. The code can be run in an IDE or online compiler to visualize the array operations.

Uploaded by

faithndlovu489
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Creating arrays and add elements to it

In Visual Basic (VB), you can create arrays of different data types (e.g., integers, strings, etc.)
and access their elements using index values. Here's a code example demonstrating how to
create arrays and access their members:

```vb
Module Module1
Sub Main()
' Creating an array of integers
Dim intArray(4) As Integer
intArray(0) = 10
intArray(1) = 20
intArray(2) = 30
intArray(3) = 40
intArray(4) = 50

' Accessing the elements of the integer array


Console.WriteLine("Integer Array Elements:")
For i As Integer = 0 To 4
Console.WriteLine("Element " & i & ": " & intArray(i))
Next

' Creating an array of strings


Dim strArray() As String = {"Apple", "Banana", "Orange", "Mango"}

' Accessing the elements of the string array


Console.WriteLine(vbCrLf & "String Array Elements:")
For i As Integer = 0 To strArray.Length - 1
Console.WriteLine("Element " & i & ": " & strArray(i))
Next

Console.ReadLine()
End Sub
End Module
```

In the code above:


- An array of integers named `intArray` is created with 5 elements, and each element is
assigned a value.
- The elements of the integer array are accessed and displayed using a `For` loop.
- An array of strings `strArray` is created and initialized with string values.
- The elements of the string array are accessed and displayed using a `For` loop, where
`strArray.Length` is used to get the length of the array.

You can run this code in an IDE or an online VB compiler to see how elements of arrays are
accessed and displayed. This example illustrates the creation, initialization, and accessing of
elements in integer and string arrays in Visual Basic.

You might also like