Sie sind auf Seite 1von 20

DEPARTMENT OF TECHNICAL

EDUCATION ANDHRA PRADESH


Name : K SREE RAMACHARYULU
Designation : LECTURER
Branch : Commercial & Comp. Practice
Institute : Govt. Polytechnic, SRIKAKULAM
Year / Semester :V
Subject : Visual Basic-I
Subject Code : CCP-503
Topic : Programming Fundamentals
Duration : 50 mts
Sub. Topic : Types of arrays
Teaching Aids : Animation Clips & Images, MS-Office
CCP503.27 1
OBJECTIVES

On completion of this period you would be


able to learn
 The different types of arrays
 Samples programs on Arrays

CCP503.27 2
RECAP

In the previous sessions you learned about


the fundamental concepts like
 Definition of an Array

 Declaration of array

 Properties of an array

 Kinds of Arrays in VB etc.,

CCP503.27 3
TYPES OF ARRAYS
Arrays are basically two types in the VB 6.0
1. Fixed size Arrays: which always remains the
same size

2. Dynamic Arrays: Whose size can change at run


time.

CCP503.27 4
FIXED SIZE ARRAYS

 The memory allocation stays the same till the end of


program’s running

 Advantage is that the memory is set aside at the


beginning of the program

 During the execution of a program there is no risk of


facing the extra memory or out of memory

CCP503.27 5
Types of Arrays on the basis of nature
of data
 Data to be stored in an array may be a single
group or in several groups.
 Based on the nature of data, arrays may be
1. Single Dimensional Array: Only one dimension
Ex: Salaries of a set of employees ages of
students of a class
2. Multi Dimensional Array: means more than one
dimension.
Ex.: Salaries of employees of different departments
Names of students of different classes

CCP503.27 6
SINGLE DIMENSIONAL ARRAY

Continuous Memory allocation to the array.


For Ex. In order to maintain List of ages of 10 3rd year
CCP students,
the array should be as follows.
Dim Age_List (10) as integer
Where Age_List is name of the array and 10 is the size of the
array..
Age_List(0) is the location to store first student Age.
Age_List(1) is for second student
……
so on
Age_List(9) is for 10th student.
CCP503.27 7
PROGRAM-SD ARRAY- DESIGN

CCP503.27 8
CODE WINDOW

CCP503.27 9
STEPS - PROGRAM DESIGN AND CODING
 Open a new Standard EXE project in design mode

 Change its name property as “Frmagelist”, its caption


property as “Application on Single Dimensional Array”

 Place one command button on the form and change its


caption property as “&Accept Ages of Students” and its
name property as “CmdAgeList”.

 Place another command button, alter its name property


as “CmdExit” and Caption property as “E&xit”

 Double-click on this command button then, VB will


display the code editor window and type the following
code in that code window
CCP503.27 10
Private Sub CmdAgeList_Click()

Dim AgeList(10) As Integer


Dim I As Integer Declares array and variable
Dim Res As Integer

For I = 0 To 9
Res = InputBox("Enter agesof student :”) Asks data and
stores in array
AgeList(I) = Res
For i=0 to 9
Next I Shows data on
Print age list (I)
screen with print
Next I statement
End Sub

Private Sub CmdExit_Click() Ends the


End program
End Sub

CCP503.27 11
 Save this program as .frmAgelist into your personal folder.

 Now run this application by click run command button at Run


menu

 Then click on Accept “Accept Ages of Students” command


button.

 Then the VB will accept List of ages of 10 Nos students one by


one.

 You will observe the input box will accept the Ages of 10
Students till the control lies in the For- Next loop

 Close the running application, and save it if we required

CCP503.27 12
 Program to find the average salary of 10 employee and the
number of employees drawing salary higher than average
salary

 STEPS :
 Open a form
 Put a command button on form and change its
name to “CmdAvg” and its caption to “More than
average salary”.

CCP503.27 13
Write the following code to click-event of
“Cmdavg”.
private Cmdavg-click ()
Dim salary (10) as long
Dim I as integer
Dim sum, Avg as long
Sum =0
Avg =0
For I =0 TO 9
Salary (I) =Input box (“give salary” ).
Sum = Sum + Salary (I)
Next I
Avg =sum/10
For I= 0TO 9
If salary (I) >Avg than print salary (I)
End if
Next I
End sub
CCP503.27 14
SUMMARY

In this session you have learnt


 the concept of an Array

 Definition of an Array

 Types of an Array

 Programs using single dimensional arrays

CCP503.27 15
FREQUENTLY ASKED QUESTIONS

1. Define an Array? How will you declare a single


dimensional array in VB?

2. List the different types of arrays?

3. Write a Program to accept the ages of N no.of


students and then print on to the form.

CCP503.27 16
QUIZ

1. What is the main purpose array?

A. Data security
B. Information Security
C. Data Storage
D. Data binding

CCP503.27 17
2. Which is the property of an array?

A. Size
B. Subscript
C. Length
D. Elements

CCP503.27 18
3. An array can store any number of values
(True/False)

Ans: True

CCP503.27 19
Assignment

1. Write a program that asks the numbers and sorts


them in ascending order

CCP503.27 20

Das könnte Ihnen auch gefallen