Arrays:

Arrays:

An Array is a group of memory locations with same name and data type of all are same like memory locations name is Arr and data type is integer. When an Array is declaring  the length of Array is would be mention. See image

 Arrays are used to store a large amount of similar type of data.For example  we  want to store a data about 100 students in a class we have to declare 100 variables. It is time consuming process to save alot of our time we declare an Array and set the length of our Array too 100.

Advantages:

  • Arrays can store large amount of data.
  • By this method we save our time.
  • Easily search process can be applied.

Declaring a one-Dimensional Array:

One dimensional array can be store a large amount of data of similar type in one row or column.

Syntax:

Syntax of declaring one dimensional array is as follows.
Dim <Array name> (length) As <type>
The Following array declares to store marks of five students:



This array can create five memory locations to store data of five students. Location number starts from 0 and end to 4. we can store five integers in this array.


Each block in array called cell. Each cell or element stored against a unique number of array that is called the index of an array and also called subscript of the element.The index is used to access a unique record for example Arr(0) is used to save record of first student and Arr(1) is used ti store record of  second student.

Variations in Array declaration:

By default, the index of Array starts from 0 but we can change this index of Array for example.
Dim Marks(1 to 5)  As integer
In this example array starts from the index of 1 and ending point of Array is 5.


by using option base 1 statement we can change the general declaration of array from one to the last limit. By using this technique the index of the array is 1 instead of 0.

Entering Data in an Array:

data can be enter in array by using the name of array an index that is display above in image but it is lengthily
and time consuming if the array is very large. For example we want to store data of 100 students the this is very lengthy. This can be solve also by loops and can also be easy.

Example-1:

write a program that uses for...next loop to take input marks of five students and give the output.
  • Start a new standard EXE project.
  • Design the form as follows.


  • double click the click event of  input button and write following code.
The Output will be print on the form.
To Download This Project Click Here.

Example-2:

Write a program that can take five numbers from user and display the sum of numbers and also display the    average of numbers.
  • Start a new standard EXE project.
  • Design the form as follows.

  • Open the click event of the button and add the following code in it. 
  • Output will be show as.
To download This Project Click Here

Example-3:

Write a VB program that get five numbers from user and store into  an array  your program display array in reverse order.
 
  • Start a new standard EXE project.
  • Design the form as follows.


  • Open the click event of button & add this code.























  • Run the project and click the button.
  • Enter any five numbers.
  • Output will be show as.






















To Download This Project Click Here.

Example-4:

  • Start a new standard EXE project.
  • Design the form as follows.
























  •  Open the click event of button & add this code.

  • Run The Project and click on button. The input box will appear for five times
  • Enter any five numbers. The original values and sorted values will displayed as follows:



No comments:

Post a Comment