Arrays: A Group of Items (String, Numbers, Dates, Image, Etc.) Arranged in Rows and Columns Is Called An
Arrays: A Group of Items (String, Numbers, Dates, Image, Etc.) Arranged in Rows and Columns Is Called An
A group of items (String,Numbers,Dates,image, etc.) arranged in rows and columns is called an Array.
End Show
List of Students
Saman
Kamal
Anil
Ranil
Sunil
Student Array
End Show
Arrays
Student(0)
Saman
Kamal
Anil
Ranil
Sunil
Arrays allow you to refer to a series of variables by the same name and to use a number (an index) to tell them apart. Visual Basic allocates space for each index number and avoids declaring an array larger than necessary
End Show
Arrays
Student(1)
Saman
Kamal
Anil
Ranil
Sunil
Arrays allow you to refer to a series of variables by the same name and to use a number (an index) to tell them apart. Visual Basic allocates space for each index number and avoids declaring an array larger than necessary
End Show
Arrays
Student(2)
Saman
Kamal
Anil
Ranil
Sunil
Arrays allow you to refer to a series of variables by the same name and to use a number (an index) to tell them apart. Visual Basic allocates space for each index number and avoids declaring an array larger than necessary
End Show
Arrays
Student(3)
Saman
Kamal
Anil
Ranil
Sunil
Arrays allow you to refer to a series of variables by the same name and to use a number (an index) to tell them apart. Visual Basic allocates space for each index number and avoids declaring an array larger than necessary
End Show
Arrays
Student(4)
Saman
Kamal
Anil
Ranil
Sunil
End Show
Cont..
End Show
Cont..
There are two types of arrays in Visual Basic
End Show
Declaring Fix size arrays There are three ways to declare a fixed-size array; depending on the scope you want the array to have:
Public array,
Use the Public statement in the Declarations section of a module to declare the array.
End Show
End Show
End Show
Declaration
StName(0) = "Saman"
StName(1) = "Kamal" StName(2) = "Ranil" StName(3) = "Sunil" StName(4) = "Nimal"
Assign values
End Sub
IT Department - National Institute of Education
End Show
Declaring & Assigning values to a local array to get Output of the contents of the array through text box
Private Sub Command1_Click() Dim StName(4) As String StName(0) = "Saman" StName(1) = "Kamal" StName(2) = "Ranil" StName(3) = "Sunil" StName(4) = "Nimal" Text1 = StName(0) Text2 = StName(1) Text3 = StName(2) Text4 = StName(3) End Sub
End Show
Declaring & Assigning values to a local array to get Output of the contents of the array through text box
Private Sub Command1_Click() Dim StName(4) As String StName(0) = "Saman" StName(1) = "Kamal" StName(2) = "Ranil" StName(3) = "Sunil" StName(4) = "Nimal" Text1 = StName(0) Text2 = StName(1) Text3 = StName(2) Text4 = StName(3) End Sub
End Show
Declaring & Assigning values to a local array to get Output of the contents of the array through text box
Private Sub Command1_Click() Dim StName(4) As String StName(0) = "Saman" StName(1) = "Kamal" StName(2) = "Ranil" StName(3) = "Sunil" StName(4) = "Nimal" Text1 = StName(0) Text2 = StName(1) Text3 = StName(2) Text4 = StName(3) End Sub
End Show
Declaring & Assigning values to a local array to get Output of the contents of the array through text box
Private Sub Command1_Click() Dim StName(4) As String StName(0) = "Saman" StName(1) = "Kamal" StName(2) = "Ranil" StName(3) = "Sunil" StName(4) = "Nimal" Text1 = StName(0) Text2 = StName(1) Text3 = StName(2) Text4 = StName(3) End Sub
End Show
Declaring & Assigning values to a local array to get Output of the contents of the array through text box
Private Sub Command1_Click() Dim StName(4) As String StName(0) = "Saman" StName(1) = "Kamal" StName(2) = "Ranil" StName(3) = "Sunil" StName(4) = "Nimal" Text1 = StName(0) Text2 = StName(1) Text3 = StName(2) Text4 = StName(3) End Sub
End Show
Declaring & Assigning values to a local array to get Output of the contents of the array through Message Box Private Sub Command1_Click() Dim StName(8) As String StName(0) = "Saman" StName(1) = "Kamal" StName(2) = "Ranil" StName(3) = "Sunil" StName(4) = "Nimal" Temp=MsgBox (StName(0) & " " & StName(1) & " " & StName(2) &_ " &_ StName(3) & " " & StName(4),,Arrays demo) End Sub
End Show
Dynamic Arrays
Sometimes you may not know exactly how large an array
A dynamic array can be resized at any time. Dynamic arrays help you to manage memory efficiently.
End Show
Declare the array with a Public statement (if you want the array to be public) or Dim statement at the module level (if you want the array to be module level), or a Static or Dim statement in a procedure (if you want the
Dynamic Arrays
Declaration
Dim StName() As String Private Sub Command1_Click() ReDim StName(3) StName(0) = "Kamal" StName(1) = "Ranil" StName(2) = "Sunil" StName(3) = "Anil" MsgBox (StName(0) & " " & StName(1) & " " &_ StName(2) &_ " & StName(3),Arrays Demo) End Sub
End Show
Dynamic Arrays
Dim StName() As String Define size Private Sub Command1_Click() ReDim StName(3) StName(0) = "Kamal" StName(1) = "Ranil" StName(2) = "Sunil" StName(3) = "Anil" MsgBox (StName(0) & " " & StName(1) & " " &_ StName(2) &_ " & StName(3),Arrays Demo) End Sub
End Show
Dynamic Arrays
Dim StName() As String Private Sub Command1_Click() ReDim StName(3) StName(0) = "Kamal" StName(1) = "Ranil" Assign values StName(2) = "Sunil" StName(3) = "Anil" MsgBox (StName(0) & " " & StName(1) & " " &_ StName(2) &_ " & StName(3),Arrays Demo) End Sub
End Show
Dynamic Arrays
Dim StName() As String Private Sub Command1_Click() ReDim StName(3) StName(0) = "Kamal" Display Values StName(1) = "Ranil" StName(2) = "Sunil" StName(3) = "Anil" MsgBox (StName(0) & " " & StName(1) & " " &_ StName(2) &_ " & StName(3),Arrays Demo) End Sub
End Show
End Show
Private Sub Command1_Click() Dim marks(7) As Integer Dim i As Integer Dim sum As Integer Dim total As Integer For i = 0 To 7 marks(i) = InputBox("Enter " & i & " Marks") Next For i = 0 To 7 total = total + marks(i) Next For i = 0 To 7 Print "Content of " & i & " Element of Array ", marks(i) Next Print "Total is ", total End Sub
End Show