Q. A.3 How to declare an array in VB? Give an example,
Answers
Answer:
Visual Basic Arrays Initialization
' Declaring and Initializing an array with size of 5.
Dim array As Integer() = New Integer(4) {}
' Defining and assigning an elements at the same time.
Dim array2 As Integer() = New Integer(4) {1, 2, 3, 4, 5}
' Initialize with 5 elements will indicates the size of an array.
How to declare an array?
Answer
Dim variable name (Size) As Variable Type
Dim Num (10) As Integer.
=> Index number is used to identify element of an array.
=> By default index number is starting from 0.
=> To change the default index number use statement option base <Number>(0,1)
How to initialize an array?
Num(0) = 5
Num(1) = 6
Num(2) =10
Num(3) = 26
...
Num(10) = 40
Private Sub Command1_Click()
Dim Num(9), x as Integer
For x = 0 to 9
Num(x) (Int (Input box ("Enter num"))
Next x
For x = 0 to 9
Print Num (x)
Next x
End Sub