0% found this document useful (0 votes)
11 views11 pages

Collections

The document provides an overview of Collections in Visual Basic, including their introduction, declaration, characteristics, and methods for adding, removing, returning, and counting items. Collections are described as flexible, object-oriented containers that allow for easy access to logically related items. Key methods and properties of collections, such as Add, Remove, Item, and Count, are explained with examples.

Uploaded by

geetikaj1408
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views11 pages

Collections

The document provides an overview of Collections in Visual Basic, including their introduction, declaration, characteristics, and methods for adding, removing, returning, and counting items. Collections are described as flexible, object-oriented containers that allow for easy access to logically related items. Key methods and properties of collections, such as Add, Remove, Item, and Count, are explained with examples.

Uploaded by

geetikaj1408
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 11

Advanced Programming with

Visual Basic

Collections

Presented By:
Ms Anita Saini
AP, BCA Department
Content to be cover

Introduction of Collections

Declaration of Collections

Collection Characteristics

Adding Items in a Collection

Removing Items in a Collection

Returning Items in a Collection

Counting Items in a Collection
Introduction of Collections

A group of logically related items

To easily 'get at' each item

Collection class provides an array-like container
more flexible than an array


It is Object Oriented Nature

Collections contain items: values or objects

Objects that have Properties and Methods

Collection access its items via a key.
Declaration

Declare a collection variable:


Dim Temperatures As New Collection


Declaration of Arrays:

Dim Salary(15) As Integer

Salary(0) = 30000

Salary(1) = 40000

Salary(2) = 50000
Collection Characteristics

It is considered an Object

It to possess Properties and Methods

Collection object : Three Methods and One
Property

- Add Method : Adds Items

- Remove Method : Deletes an items by index
or key

- Item Method : Returns an item by index or key

- Count Property : Returns the number of Items
Collection Characteristics

Visual Basic Collections Types:

- Systems Collections

- Programmer defined Collections.

In Systems Collections :

- Forms Collection and Controls Collection.


Visual Basic automatically 'adding' newly
loaded Forms to the Forms Collection

Controls you place on the form - automatically
'added' to the Controls Collection.

Adding Items in a Collection

Add Method : adds new items to the collection.

Syntax :

 Collection.Add value,[key],[before],[after]


e.g: Temperatures.Add 78, “KUK”


Temperatures.Add 79, “YNR”, , “KUK”


Temperatures.Add 79, “YNR”, , after : = “KUK”


Collections aren’t sorted

Removing Items in a Collection


Remove Method : remove an item

 Object.Remove key

Object.Remove index

e.g : Temperatures.Remove “KUK”

Temperatures.Remove 6
Returning Items in a Collection


Item Method :

Object.Item key

 Object.Item index

e.g : Temperatures.Item(“YNR”)

It is the default method

So, omit it when access an item in a collection

like, Temperatures(“YNR”)


Counting Items in a Collection


Conut Property : returns the number of items

 Object.Count

Count use to scan all the elements of the
collection with a For ......Next Loop

like,

For city = 1 to Temperatures.count


{ Process elements }
Next city
Example


To store the city names and temperatures using
collections

You might also like