| HTML Tutorials |
|
|
| XML Tutorials |
|
|
| Browser Scripting |
|
|
| Server Scripting |
|
|
| .NET (dotnet) |
|
|
| Multimedia |
|
|
| Web Building |
|
|
| Java Tutorials |
|
|
| Programming Langauges |
|
|
| Soft Skills |
|
|
|
|
Introduction to Arrays
|
|
By definition, an array is a list of variables, all with the same name and data type.
We only need to use one variable,when we work with a single item.
However, if we have a list of items which are of similar type to deal with and then we need to declare an array of variables instead of using a variable for each item.
For example, if we need to enter one hundred names, instead of declaring one hundred different variables, we need to declare only one array and we differentiate each item in the array by using subscript, the index value of each item, for example name(1), name(2),name(3) .......etc.
|
|
Declaring Arrays
|
|
We could use Public or Dim statement to declare an array just as the way we declare a single variable. The Public statement declares an array that can be used throughout an application while the Dim statement declare an array that could be used only in a local procedure.
The general format to declare an array is as follow:
|
|
Dim arrayName(subs) as dataType
|
|
|
where subs indicates that the last subscript in the array
|
|
The following is an example of using array in VB:
|
|
Dim Count(100 to 500) as Integer
|
|
|
declares an array that consists of the ends at Count(500) and first element starting from Count(100)
|
|
The following example is a sample program of using array:
|
Dim studentName(10) As String
Dim num As Integer
Private Sub addName()
For num = 1 To 10
studentName(num) = InputBox("Enter the student name", "Enter Name", "", 1500, 4500)
If studentName(num) <> "" Then
Form1.Print studentName(num)
Else
End
End If
Next
End Sub
Private Sub Exit_Click()
End
End Sub
Private Sub Start_Click()
Form1.Cls
addName
End Sub
|
|
|
The above program displays the entries in the form itself and accepts data entry through an input box. As you can see, this program will only allows a user to enter 10 names each time he click on the start button and the interface of the above program is as follows:
|
|
|
The above program accepts data entries through an InputBox and displays the items in the form of a list box.
|
Share And Enjoy:These icons link to social bookmarking sites where readers can share and discover new web pages.
Keywords:
Arrays in VB,
arrays in vb 6.0,
control arrays in vb,
dynamic arrays in vb,
arrays in vb net,
arrays in vb6,
redim in vb,
array in vb net,
array in vb,
visual basic arrays,
arrays in visual basic,
array in vb6,
visual basic net arrays,
visual basic 6 arrays,
string array in vb net,
string array in vb,
dynamic array in vb
|
|
| HTML Quizes |
|
|
| XML Quizes |
|
|
| Browser Scripting Quizes |
|
|
| Server Scripting Quizes |
|
|
| .NET (dotnet) Quizes |
|
|
| Multimedia Quizes |
|
|
| Web Building Quizes |
|
|
| Java Quizes |
|
|
| Programming Langauges Quizes |
|
|
| Soft Skills Quizes |
|
|
|