In: Computer Science
can anyone give me an example of an Array and its usage in Visual Basic programming
Array:
-> An array is a collection of elements of the same data type in Visual Basic programming.
-> It is used to store elements and one variable of an array can store multiple values, unlike normal variables.
-> Mostly used arrays are one-dimensional array and two-dimensional array.
-> One-dimensional array is used to store elements either row-wise or column-wise.
-> Two-dimensional array is used to store elements in tabular form.
Real-life examples of an array:
1) an array of eggs
2) Roll numbers of all the students of the same class(all roll numbers have the same data type ).
Example: VB
program to store 5 integers in an array and display as
stored.
Program:
Private Sub Command1_Click()
'declaration of an array
Dim arr(5) As Integer
Dim i As Integer
'storing 5 integers into the array
For i = 0 To 4
arr(i) = CInt(InputBox("Enter an integer: "))
Next i
' displaying the elements of the array into the textbox
For i = 0 To 4
txtArray.Text = txtArray.Text & arr(i) & vbNewLine
Next i
End Sub
Output:

