Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 13

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 : Sample Programs on Arrays.
Teaching Aids : PPT, Animation Clips & Images
CCP503.30 1
Objectives
On completion of this period, you would be
able to know more about

 Writing programs on Single dimensional Array

 Writing programs on Multi Dimensional Arrays

 Using ReDim statement

CCP503.30 2
RECAP

 Types of arrays,

 Multi-dimensional arrays

CCP503.30 3
Program1 on Arrays
Write a program to accept a list of 10
numbers and compute its sum, print
them on to the form with its sum.

CCP503.30 4
Follow the steps to develop an application
On array:

 Open a new Standard EXE project in design


mode
 Change its name as Form1 and its caption as
“Application on Arrays”
 Place a command button on the form and
change its caption as “&Do” & its name as
“CmdDo”
 Double-click on command button then, we get
the code editor window and type the following in
that code

CCP503.30 5
Private sub CmdDo_Click()
Dim I as Integer
Dim Arr(10) as Integer
Dim s AS Long
For I = 0 to 9
Arr(I) = InputBox(“enter a number “)
Next I
For I = 0 to 9
S = S + Arr (I)
print Arr(I)
Next I
End sub

Print “Sum of the list of given Numbers: “ & s

 Now run application, click at the command button at run time


 Program asks ten numbers, and get summation of them, print them on to the
form and then shows the cumulative of totals.
 Observe the changes by clicking at the command button

CCP503.30 6
Program2 on Arrays to accept a list of
numbers, and sort them in an
ascending order using Bubble Sort
Technique.

CCP503.30 7
Program to sort a set of value
 Create a form and paste a command button with name cmdsort
 Write the following code to the command button and run the program and see
Private sub Cmdsort_click ()
Dim m (5) as integer
Dim I as Integer, J as Integer
Dim d as Integer
for I = 0 to 4
m (I) = Inputbox (“Give a no:”)
next I
for I = 0 to 3
for J = I + 1 to 4
If m (I) > m (J) Then
d = m (I)
m (I) = m (J)
m (J) = d
End if
Next J
Next I
for I = 0 to 4
PRINT m (I)
Next I
End sub
CCP503.30 8
Summary
In this Session, you have learnt about
 writing sample programs on Arrays in VB

CCP503.30 9
Frequently Asked Questions

1. Explain the concept of arrays, using an example.

CCP503.30 10
QUIZ
1 Dim I as Integer
Dim Arr[10] as Integer
For I = 1 to 10
Arr = input box (“give a no;”)
Next I
In which line is there an error
A. 2
B. 4
C. 5
D. 7

CCP503.30 11
2. Find the error from the following
code, in which line it is?
For i=0 to 2
For j=0 to 2
print “ GTPSKLM”
next I
next I
F. First line
G. Second Line
H. Third line
I. Fourth line
J. Fifth line
CCP503.30 12
Assignment

1. Write a program that asks ten numbers and sort


them in descending order and shows the fourth
highest number

CCP503.30 13

You might also like